【问题标题】:Error: Computed property was assigned to but it has no setter错误:已分配计算属性,但没有设置器
【发布时间】:2020-07-09 23:19:28
【问题描述】:

我在 mapGetters 中用于从商店获取参数,

 computed: {
    ...mapGetters("agent",["getConfig"]),
}

运行良好,但出现错误:

[Vue 警告]:已分配计算属性“getConfig”,但没有设置器。

我试过用 Get 和 Set 来做:

computed: {
getConfig: {
    get: () => this.$state.getters.getConfig,
    set: (value) => this.$state.commit('setConfiguration', value ) }}

但我有错误:

vue.runtime.esm.js:620 [Vue 警告]:观察者“getConfig”的 getter 错误:“TypeError:无法读取未定义的属性 '$state'”

在计算中为“GetConfig”生成 Get 和 Set 的正确语法是什么?

【问题讨论】:

    标签: vue.js


    【解决方案1】:

    this 的上下文在 arrow functions 中丢失。

    所以改成:

     get: function() { 
       return this.$state.getters.getConfig
     },
     set: function(value) {
       this.$state.commit('setConfiguration', value ) 
     }
    

    【讨论】:

      猜你喜欢
      • 2019-05-21
      • 2020-10-04
      • 2018-09-26
      • 2021-03-17
      • 2020-11-07
      • 2020-07-18
      • 2020-10-23
      • 2018-02-16
      • 2018-12-14
      相关资源
      最近更新 更多