Answer the question
In order to leave comments, you need to log in
Value not being recorded?
There is a component - a large form
data: {
return {
form: {
// тут объект с глубокой вложенностью
},
}
}
async getDataFromApi({ commit }) {
const res = await axios.get('url');
if (res.data) {
commit('mutationName', res.data);
}
return res;
},
methods: {
...mapActions('api', ['getDataFromApi']),
getData() {
this.getDataFromApi().then(res => {
if(res.status === 200 && res.data) {
this.form = res.data; // тут this.form остается прежним, не меняется
}
})
},
},
Answer the question
In order to leave comments, you need to log in
Is this the whole code?
If so, then everything is simple, you do not call the method anywhere - getData () is the time.
Two - this method (getData() ) is not needed at all, since
...mapActions('api', ['getDataFromApi']), - has already added the getDataFromApi method, so
in the end you need to do it in the created/mounted hook or in another method call
methods: {
...mapActions('api', ['getDataFromApi']),
},
created() {
this.getDataFromApi().then(res => {
if(res.status === 200 && res.data) {
this.form = res.data; // тут this.form должен изменится
}
})
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question