记得在index里挂载siteStore
const siteStore = {
namespaced: true,
state: ()=>({
refresh:false,
}),
getters: {
},
mutations: {
UPDATE_SITE_LIST(state,refresh){
state.refresh = refresh
}
}
}
export default siteStore;
页面修改值
监听vuex变化
!!watch是有变化才可以监听到,所以值要回置到初始状态
computed:{
refresh(){
return this.$store.state.siteStore.refresh
}
},
watch: {
refresh(newVal,oldVal){
console.log('监听到变化',newVal,oldVal);
this.getDataByBuoyType()
}
},
写法二:直接监听,不通过computed
'$store.state.siteStore.refresh'(val,oldVal){
console.log('监听到变化',val,oldVal);
},