Stories

Detail Return Return

vue 使用computed報錯 .. was assigned to but it has no setter. - Stories Detail

問題:

 <a-radio @change="chooseOther" v-model="tempReadio">其他</a-radio>
 
 computed: {
    tempReadio() {
      if (this.reasonValue == 7) {
        return true;
      } else {
        return false;
      }
    },

因為我們平時綁定的都是data裏面的數據 ,當這個value值是冬天的時候, 嚴格模式下 此時就會報錯
image.png

解決方法: 手動添加set 就好了

  computed: {
    tempReadio: {
      get() {
        if (this.reasonValue == 7) {
          return true;
        } else {
          return false;
        }
      },
      set(val) {},
    },
  },

vue 官網也有給到解釋,關於v-model綁定了vuex 或者 computed的時候,需要自己設置get和set即可
https://vuex.vuejs.org/zh/gui...

user avatar yelloxing Avatar 6fafa Avatar rk405264704 Avatar taotao123 Avatar nihaoanihao Avatar songxianling1992 Avatar huaiyug Avatar patelo Avatar fisher_feng Avatar witersen Avatar minghuajiwu Avatar lantianhaijiao Avatar
Favorites 43 users favorite the story!
Favorites

Add a new Comments

Some HTML is okay.