我在历史模式下使用vue-router . 当我在子路径"/dashboard"上并刷新页面时, 组件被挂载两次 . 在ccp组件中,我是控制台登录创建和挂载的挂钩 . 我看到每个控制台输出两次 . 有什么想法吗?在此先感谢您的期待!
编辑:在初始应用程序加载时,创建 并仅挂载一次 .
这是代码:
App.vue:
// blah blah blah - doing stuff and then pushing route to /dashboard
return this.$router.push({name: "dashboard"});
router.js
export default new Router({
mode: "history",
routes: [
// DEFAULT ROUTE
{
path: "/",
name: "root",
alias: store.getters.isDemoMode ? "/demo" : "/app" // isDemoMode is false for this test however I wanted to show the alias config in case that is part of the problem.
},
{
path: "/demo",
name: "demo",
component: Demo
},
{
path: "/app",
name: "app",
component: App,
children: [
{
path: "/dashboard",
name: "dashboard",
component: Dashboard
}
]
}
})