报错
store中actions向mutation传递时控制台报错,'commit' is not defined.
分析
主要的原因是 categoryList方法里面没有 commit这个方法。为什么没有?其实它是有的,只不过在 ()
里面,报错可能是直接写 commit(xxx)
了
解决
在actions中 categoryList 方法参数添加{commit}
,解决。
const actions={
async categoryList({
commit}){
let result = await reqCategoryList();
// console.log(result);
if (result.code == 200) {
commit('CATEGORYLIST',result.data)
}
}
}