我正在使用 vue-menu
组件,并使用它在不同的路线之间切换。切换到另一条路线后,我想在下拉标题上显示当前路线名称,如下所示:
我尝试过使用生命周期方法,例如 beforeCreate 、created、mounted...
等,但没有一个被调用。我怎样才能达到预期的结果?
最佳答案
你应该使用“ watch ”
data() {
return {
routeName: null,
};
},
watch: {
'$route': 'currentRoute'
},
methods: {
currentRoute() {
this.$nextTick(() => {
this.routeName = this.$route.name
});
}
},
关于vue.js - Vuejs获取当前路由名称并显示在菜单上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55682975/