Vuejs致力于突变失败(Vuejs commit to a mutation fails)
这是我如何执行提交,但数据永远不会传递
const actions ={ updateBtn({commit}, data){ commit("test", data); console.log("data is"+data);//data here has a value } } const mutations={ test(state, {data}){ console.log(data) //this is always undefined. } }我在哪里突然出错了
This is how am performing commit but data is never passed through
const actions ={ updateBtn({commit}, data){ commit("test", data); console.log("data is"+data);//data here has a value } } const mutations={ test(state, {data}){ console.log(data) //this is always undefined. } }Where am i going wrong in the mutations
最满意答案
尝试不使用函数参数这样使用。
const actions = { updateBtn({commit}, data){ commit("test", data); console.log("data is"+data);//data here has a value } } const mutations = { test(state, data) { console.log(data); state.data = data; } }Try using like this without function parameter.
const actions = { updateBtn({commit}, data){ commit("test", data); console.log("data is"+data);//data here has a value } } const mutations = { test(state, data) { console.log(data); state.data = data; } }更多推荐
发布评论