vuex 中异步请求和同步请求更改store
同步请求使用:mutations
mutations: {
increment(state){
state.counter++
},
incrementcounter(state,count){
state.counter+=count
},
addper(state,student){
state.data_lst.push(student)
},
updateage(state){
state.data_lst[2]['address'] = 'hubei'
}
},
actions: {
aaddper(context,student){
setTimeout(()=>{
context.commit('addper',student)
},1000)
}
},
异步使用:actions
先调用 mutations中的方法,如 aaddper 函数
使用方则直接 dispathch 调用aaddper
btncli2(count){
this.$store.dispatch('aaddper',count)
},
浙公网安备 33010602011771号