解决this._data.$$state...“Error: [vuex] do not mutate vuex store state outside mutation handlers.“ 报错
今天遇到了这样一个报错:[Vue warn]: Error in callback for watcher "function () {return this._data.$$state;}": "Error: [vuex] do not mutate vuex store state outside mutation handlers."javascript:void(0)使用场景是这样的:th
·
今天遇到了这样一个报错:
[Vue warn]: Error in callback for watcher "function () {
return this._data.$$state;
}": "Error: [vuex] do not mutate vuex store state outside mutation handlers."javascript:void(0)
使用场景是这样的:
this.$store.commit("business/set_state", {
key: maxPage,
value: this.$store.state.business[maxPage]++,
});
在这个地方 使用了++,导致直接修改this.$store.state中的数据,解决方法就是+1啦!
当项目够大,代码逻辑复杂一点的时候,像这种小的问题 有时候很难发现,在这里记录一下,以后遇到[vuex] do not mutate vuex store state outside mutation handlers. 这样的错误,就先去找直接修改this.$store.state参数的地方!
所以我们在写代码的时候一定要细心细心在细心,不然等待你的将是漫长的找bug之路~~~~
更多推荐


所有评论(0)