【问题标题】:Vue Js-Error in callback for watcher "function () { return this._data.$$state }": "Error: [vuex] do not mutate vuex store state outside mutationVue Js-Error in callback for watcher "function () { return this._data.$$state }": "Error: [vuex] do not mutate vuex store state outside mutation
【发布时间】:2022-01-24 02:12:14
【问题描述】:

Screenshot of the error I get in the console

The method I use

In mounted

MapState in the Computed

我的代码正在运行。但我不明白这个错误。我找不到解决方案。我请求你的帮助。

【问题讨论】:

    标签: javascript vue.js vuejs2 frontend


    【解决方案1】:

    这是因为你在突变之外改变了状态,它就在那里:

    this.systemstatus.splice(i, 1)
    

    您可以使用扩展运算符复制systemstatus,例如:

    const systemStatusCopy = [...this.systemstatus]
    

    你不会得到任何错误,但是状态也不会改变,但如果你需要在商店中改变它,那么添加突变并在你需要的时候提交一个突变。

    【讨论】:

    • 谢谢大卫。有了你的解决方案,问题就解决了。
    猜你喜欢
    • 1970-01-01
    • 2019-10-19
    • 2017-06-10
    • 2022-12-26
    • 2020-05-02
    • 2020-12-23
    • 2020-07-27
    • 1970-01-01
    • 2021-02-28
    相关资源
    最近更新 更多