解决this.

解决this.,第1张

今天遇到了这样一个报错:

[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之路~~~~

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1321325.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-12
下一篇2022-06-12

发表评论

登录后才能评论

评论列表(0条)

    保存