Answer the question
In order to leave comments, you need to log in
Vue.js automatic update of model in store?
Hello,
something is completely confused and I do not understand why this is happening. The crux of the matter - I have a form in which you can set the "width" parameter. The form should only work when the button is clicked. In fact, it happens that after we clicked the confirmation button 1 time and sent the data to our store (vuex), we can simply change the value in the input field and the data in vuex itself starts to change.
<div class="row">
<div class="col-md-12">
<label for="namespace-width">Width:</label>
<input id="namespace-width" type="number" placeholder="Width" v-model="namespaceSize.width" @change.prevent @input.prevent/>
</div>
<div class="btn btn-success" @click="updateNamespacesSize()">Apply</div>
</div>
namespaceSize: {
width: null,
heigth: null,
length: null
},
updateNamespacesSize() {
return this.$store.dispatch('updateSize', {type: 'Namespace', size: this.namespaceSize})
},
updateSize: (context, payload) => {
return context.commit('updateSize', payload)
}
dateSize: (state, payload) => {
console.log('update size')
switch (payload.type) {
case 'Namespace': return state.namespaces.forEach(namespace => { namespace.size = payload.size })
case 'Class': return state.classes.forEach(clas => { clas.size = payload.size })
case 'Method': return state.methods.forEach(method => { method.size = payload.size })
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question