[Vue warn]: Computed property "activeMetricName" was assigned to but it has no setter.

在这里插入图片描述
activeMetricName,在父页面,是个计算属性,作为props传到子页面,子页面还可以修改它。
这个报错,计算属性默认只有 getter ,双向数据绑定的时候,修改了它的值,不过在需要时你也可以提供一个 setter :
改之前:

 activeMetricName () {
      let metric = ''
      if (this.c_itemAlarmInfo && this.active_index) {
        metric = this.c_itemAlarmInfo[this.active_index].metricName
      } else {
        metric = COUNT
      }
      return metric
    },

改之后:

activeMetricName: {
      get () {
        let metric = ''
        if (this.c_itemAlarmInfo && this.active_index) {
          metric = this.c_itemAlarmInfo[this.active_index].metricName
        } else {
          metric = COUNT
        }
        return metric
      },
      set (val) {
        this.$emit('update:value', val)
      }
    },

猜你喜欢

转载自blog.csdn.net/weixin_36430673/article/details/103366660