繁体   English   中英

路由是用名称声明的,但是 this.$route.name: undefined

[英]Routes is declared with name but this.$route.name : undefined

我在一个 Django 项目之上使用 Vue3 CDN,我在其中添加了 VueRouter,它工作得非常好,直到我决定向路由对象添加名称。

在我的主要组件内部,我试图在每次用户访问页面时检查路由名称的值。

const routes = [
{ 
    path: '/',
    name: 'home',
    component: home 
},
{
   path: '/our-program'
   name: 'program',
   component: 'program'
}
]

const router = VueRouter.createRouter({
history: VueRouter.createWebHashHistory(),
// mode: history,
routes,}); 


const app = Vue.createApp({
data() {
    return {}
},
 computed:{
    isFocus(){
        return this.$route.name;
    }
},
mounted() {
    console.log(this.$route);
    },
});

const vm = app.use(router).mount('#pages');

我在控制台中获得了路径,但 $route.name 似乎没有通过。 没有人知道我做错了什么吗? 在此处输入图像描述

this.$route.name 可以从子组件中显示,而不是像我试图做的那样从实际的根组件中显示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM