vue.js - 用状态管理去控制首页的菜单显示,但是不成功。
本文介绍了vue.js - 用状态管理去控制首页的菜单显示,但是不成功。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
APP.vue-----------------------
<template v-if="navShow==-1">
<Navigation></Navigation>
</template>
computed: {
navShow(){
return this.$store.getters.navShow
}
}
store.js-------------------
state: {
navShow: null ,//导航是否显示
}
mutations: {
navShowNo(state){
state.navShow= -1; //-1为不显示导航
}
}
getters: {
navShow: state => {
return state.navShow
}
}
actions: {
navShowNo ({commit}) {
commit('navShowNo');
}
}
wx.vue-------------
created(){
this.$store.dispatch("navShowNo");
//console.log(1)
console.log(this.$store.state.navShow)
}
this.$store.state.navShow中的值确实变了,但是菜单还是不隐藏
解决方案
v-if='navShow == -1'
这个判断不是为true吗?
为true当然不隐藏啊
这篇关于vue.js - 用状态管理去控制首页的菜单显示,但是不成功。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文