You can create a plugin to store some settings:
./Components/config/index.js
import Vue from 'vue'
const globalConfig = new Vue({
data: {
menu: {
show: true,
hide_from_pages: [ 'Contact' ]
}
},
methods: {
show_or_hide: function(page) {
this.menu.show = this.menu.hide_from_pages.includes(page) ? false : true;
}
}
});
globalConfig.install = () => {
Object.defineProperty(Vue.prototype, 'globalConfig', {
get () { return globalConfig }
});
};
export default globalConfig
Import into the file main.js
...
import globalConfig from './config'
...
Vue.use(globalConfig);
Add the function scrollBehavior
at your time VueRouter
calling the method show_menu
, pass as parameter the name of the loaded page.
new Router({
routes: [
{ path: '/', name: 'Home', component: Home },
{ path: '/about', name: 'About', component: About },
{ path: '/contact', name: 'Contact', component: Contact },
],
scrollBehavior (to, from, savedPosition) {
globalConfig.show_menu(to.name)
}
})
Use the directive v-show
in the component:
<menuv v-show="globalConfig.menu.show"></menuv>
References
Face it involves a much larger context than this code you have put here. Basically you will have to put a v-if in the menu tag validating according to the route.
– LeAndrade
~Utilize
vuex
~– Valdeir Psr