watch侦听vuex值的变化
watch:{
"$store.state.loginStore.menu":{
handler:function(newVal,oldVal){
console.log(newVal,oldVal)
if(this.$store.state.loginStore.menu.length>0){
this.$router.push({path:"/"})
}
}
}
}
在vuex当中的modules模块当中有loginStore这个自己定义的模块
获取vuex值的时候得带上模块名,因此是这个$store.state.loginStore.menu
menu就是vuex当中state当中存的一个变量