1
我试图根据路径是否在给定路径上隐藏主应用程序导航栏。基于Vue中的路径路径或参数隐藏元素
在我的App.vue组件中,在created()
方法中。我检查路线是否是x || Ÿ,如果其中任何一个是真的,我将我的Vuex状态show
设置为false。如果除了这两条之外还有其他路线,我会设置show = true
。
然后在我的模板,我做这个
<template>
<div id="app">
<navigation v-show="show"></navigation>
<router-view></router-view>
</div>
</template>
我注意到在Vuex工具,我的突变,甚至没有注册,所以我不知道这是为什么。他们需要做的是行动吗?这是我的完整代码。
<template>
<div id="app">
<navigation v-show="show"></navigation>
<router-view></router-view>
</div>
</template>
<script>
import Navigation from './components/Navigation/Navigation'
import { firebaseAuth } from './firebase/constants'
import store from './store/index'
export default {
name: 'app',
components: {
Navigation
},
computed: {
show() {
return store.state.navigation.show
}
},
created() {
// Checks for a user and dispatches an action changing isAuthed state to true.
firebaseAuth.onAuthStateChanged(user => {
console.log(store.state.authentication);
console.log(user);
store.dispatch('checkUser', user);
});
// Check if given route is true, if it is then hide Nav.
if (this.$route.path === "/dashboard/products" || this.$route.path === "/dashboard/settings") {
store.commit('hideNav');
} else if (this.$route.path !== "/dashboard/products" || this.$route.path !== "/dashboard/settings") {
store.commit('showNav');
}
}
};
</script>