【发布时间】:2020-10-04 10:29:45
【问题描述】:
在应用程序中包含nav 组件,我想要做的是,如果您不是通过主页访问网站,而是从子页面例如some_url/boys 它在导航中选择该块。所以我在想什么获取路由器名称的最佳方法?我想可能直接在Nav 组件中借助beforeRouteUpdate 钩子获取路由器的名称,但它根本不想输入它。这是我的组件的逻辑
import MenuBar from "@/store/menu.js";
export default {
namespaced: true,
name: "TheNav",
data(){
return {
menu: MenuBar.navBar
}
},
beforeRouteUpdate (to, from, next) { // dosn't print anything!
console.log(1);
console.log(this.$route.name);
next()
},
methods: {
ft_click(e, i) // that's animation method, nevermind
{
this.menu.forEach( (el) => {
el.styleNavBar.width = 0 + '%';
el.active = false;
})
this.menu[i].active = true;
this.menu[i].styleNavBar.width = 80 + '%';
},
ft_hover(e, i, width) // that's animation method, nevermind
{
if(this.menu[i].active !== true)
this.menu[i].styleNavBar.width = width + '%';
}
}
}
同样的问题,如何在 Vue 中获取路由器的当前名称?或者为什么我的钩子不想工作(((
【问题讨论】:
标签: vue.js vue-component vue-router