vuex方法一:
data(){
return {
stepMap:0
}
},
computed:{
currentStep:{
get(){
return this.stepMap
},
set(v){
this.stepMap = v
}
// set方法只写下面这一行也是可以的
// set(){}
}
}
如果方法一不行,试试方法二,用action改变state属性
store文件
state: {
list: '',
},
mutations: {
setList: (state, list) => {
state.list = list
}
},
actions: {
setListAction: ({ commit }, list) => {
commit('setList', list)
}
}
vue文件
import { mapState ,mapActions} from 'vuex'
computed: {
...mapState({
list: (state) => state.business.list
})
},
methods: {
...mapActions('business', ['setListAction']),
change(){
this.setListAction(newList)
}