我在 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 似乎无法通过。 难道没有人知道我做错了什么吗?