使用Vuex遇到的问题 2018-11-07
2018-11-07 本文已影响4人
菜鸟搬砖
Computed property "index" was assigned to but it has no setter.
报错原因是在这个值有可能被改变时,你没有配置setter。
自己在store内写了之后,发现也没有用。
最后在百度一波之后发现,set是直接写在computed内的:
computed:{
index:{
get(){
return this.$store.state.index;
},
set(val){ //val就是你改变的值
this.$store.commit("index",val);//调用store内的mutations方法
}
}
}
OVER!!!