(已解决)vue2报错:promise拒绝时暂停 ReferenceError: ‘commit‘ is not defined.

报错

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)
        }
    }
}

猜你喜欢

转载自blog.csdn.net/yolo_______95/article/details/127664491