I'm trying to extract array from Vuex, edit it locally, then:
- Discard changes without changing the Vuex array, or
- Submit local changes (to backend).
At this point, editing the local array is also updating the array in Vuex -- which I don't want to.
When I edit the data on the form and return (without submit), the changes are also carried over the the array in Vuex instead of only modifying the local array.
Quick recap of my code:
Store:
var app = new Vue({
el: "#app",
store: new Vuex.Store({
state: {
details: [ /* data */ ]
}
})
});
HTML:
Note: Here I can see in what the default values are before edit.
<b-form>
// I'm using the item and index later on
<div v-for="(item, index) in data">
// Just want to see what the default values are before editing
<b-form-input v-model="form.title"></b-form-input>
</div>
</b-form>
Script:
data() {
return {
data: null,
form: null
}
},
beforeMount() {
this.data = [...this.$store.state.details]
this.form = this.data[0];
}
How can I improve my code, so that I can make changes locally?