话不多说,直接上代码,创建,声明,监听,
<el-menu
class="dash-menu"
unique-opened
background-color="red"
text-color="white"
active-text-color="white"
:default-active="navselected"
:active="navselected"
router
@open="handleOpen"
@close="handleClose"
>
data(){
return{
navselected: this.$store.state.selectMenuIndex,
}
},
watch: {
// 监测store.state
'$store.state.selectMenuIndex':'getNavType'
},
methods: {
getNavType(){
this.navselected=this.$store.state.selectMenuIndex;
if (this.navselected == "2-1") {
this.$router.push({ path: "/home-cake" });
}else if(this.navselected == "2-2") {
}else if(this.navselected == "3") {
}
},
}
缓存部分
state.js
var vstate = {
selectMenuIndex: "1",//默认选中页面index
}
export default vstate
getters.js
const vgetters = {
getSelectMenuIndex:state => state.selectMenuIndex,
}
export default vgetters
其他页面点击按钮操作
clickAction(){
this.$store.state.selectMenuIndex = "2-1";
},