Answer the question
In order to leave comments, you need to log in
Why doesn't VUEX change state in actions?
const store = new Vuex.Store({
state: {
test_value: null,
},
mutations: {
set_test_value(state, n) {
state.test_value = n;
},
},
getters: {
get_test_value: state => state.test_value,
},
actions: {
reg_test_value({ commit }) {
axios.post('/site')
.then((response) => {
if (response.data) {
state.test_value = response.data.test_value; // response.data.test_value = 999
// или commit('set_test_value', response.data.test_value)
// пробовал и так и так
}
});
},
},
modules: {
},
});
Answer the question
In order to leave comments, you need to log in
if (response.data) {
commit('set_test_value', response.data.test_value)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question