在使用vue時遇到了這個問題,主要就是使用computed時只設置了get,而沒有設置set,設置的方式很多,如果只修改在當前組件, 直接等於value就行了。
uploadRate:{
get () {
return this.$store.state.Set.uploadRate;
},
set (value) {
this.$store.state.Set.uploadRate=value;
}
}
如果想通過修改當前組件的值,進而修改vuex當中的值,可以在當前組件computed中使用:
uploadRate:{
get () {
return this.$store.state.Set.uploadRate;
},
set (value) {
this.$store.commit('JISUAN_SET_uploadRate', { v: value });
}
},
然后在vuex當中寫:
JISUAN_SET_uploadRate (state, {
v
}) {
state.uploadRate = v
}
以上是較為常見的兩類,但其中的value該等於什么則不固定,可以根據自己的需求來寫