VueJS: Computed property "hoge" was assigned to but it has no setter

環境:

vue@2.6.12

 

computed propertyをメソッドで直接定義し直したら

Computed property "hoge" was assigned to but it has no setter

とエラー

 

computed property を再定義する場合、あらかじめ該当するproperty に setter, getter を設定しておく必要がある。

 

data() {

  return {

    bar: "initial value"

  }

}

computed: {

  foo: {

    get() {

      return this.bar

    },

    set(newValue) {

      this.bar = newValue

    }

  }

},

methods: {

  changeComputedProp() {

    this.bar = "change computed prop by method"

  }

}

 

 

ref)

vuejs.org

katuo-ai.com