Answer the question
In order to leave comments, you need to log in
How to correctly set the initial state of a component from Vuex?
I need to take data from Vuex when initializing components, then change it inside the components, and then update it in Vuex if necessary.
A simple first question - if I need the initial structure of a variable, is it correct to set it like this in Vuex?
export default new Vuex.Store({
state: {
currentNote: {
id: 1,
title: '',
list: [
{
isDone: false,
text: "",
id: 1
}
]
}
},
export default {
data() {
const {currentNote, currentListId} = this.$store.state;
return {
title: currentNote.title,
items: currentNote.list.slice(),
};
},
Answer the question
In order to leave comments, you need to log in
Why I copy the data for the component is so that for every input change in the component - not to be processed on the Vuex side
const copy = JSON.parse( JSON.stringify( source ) )
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question