[vuex] unknown action type: countAddAction
七娃博客273人阅读
明明按步骤写的vuex的actions方法,为什么会报错未知呢?原来没有加上命名空间的名字
vuex的actions方法如下:
namespaced: true, state: { content: 0, }, ... actions: { countAddAction(context){ context.commit("add") }, countCubtractAction(context){ context.commit("subtract") } }
外部更改content的值:
就可以用dispatch调用actions里的方法
this.$store.dispatch('count/countAddAction');
也可以直接修改
this.$store.count.content++
这样就可以修改vuex的state对应的值了,自己搭建环境很容易忘啊,发现一直在学基础和忘基础的路上,脑子不好使了,离退休不远了吧。
评论 | 0 条评论
登录之后才可留言,前往登录