Computed property “XXX” was assigned to but it has no setter错误

时间:2024-03-28 15:09:49

当你使用Vuex中state中状态时,在Vue中使用了v-model绑定数据报错

Computed property “XXX” was assigned to but it has no setter错误

 

Computed property “XXX” was assigned to but it has no setter错误

Computed property “XXX” was assigned to but it has no setter错误

 原因

  1. 组件中v-model=“XXX”,而XXX是vuex state中的某个变量
  2. vuex中是单项流,v-model是vue中的双向绑定,但是在computed中只通过get获取参数值,没有set无法改变参数值

解决

在computed中添加get和set

Computed property “XXX” was assigned to but it has no setter错误

将v-model改成:value