vuex mutations 代码
state: {
showLaser:true,
showPath:true,
showCamera:true,
},
mutations: {
setState(state,opt){
for(let [key,val] of Object.entries(opt)){
state[key] = val;
}
}
}
使用
this.$store.commit('setState',{
showLaser:false,
showCamera:false,
showPath:false,
})
这样就不要每次设置state值时写一个对应的更新state方法了。