B
B
be_a_man2019-01-21 14:25:09
Vue.js
be_a_man, 2019-01-21 14:25:09

What's the best way to do it with Vue.js?

There is a step by step form. What fields will be at each step comes in JSON'e => stored in Vuex.
At each step, you need to check the fields for validity / required (if it is) and signal the parent to activate / deactivate the Next button.
The filled data is written in state to an array.
1) How to optimally listen to the fields and signal to the parent?
2) How to optimally render all the steps at once and scroll through them back and forth or when clicking on Next Prev one at a time?
5c45abe38f757470475965.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Askhat Bikmetov, 2019-01-21
@be_a_man

1. The change events on the field modify the state of the component, on which the computable properties that determine whether the form is valid or not depend.

Example
<template>
  <form>
    <input v-model="text" />
    <button :disabled="!isValid">Submit</button>
  </form>
</template>
<script>
export default {
  data() {
    return {
      text: ''
    }
  },
  computed: {
    isValid() {
      return validator(this.text)
    }
  }
}
</script>

2. Depends on whether all fields should be rendered unconditionally or optionally.
Difference between v-if and v-show
v-if не отрендерит разметку никогда, если её биндинг не вернёт true.
v-show отрендерит разметку, но в зависимости от своего биндинга установит display: hidden на элемент.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question