我有一个 vue 应用程序,其路由器设置如下:
import index from './components/index.vue';
import http404 from './components/http404.vue';
// module lazy-loading
const panda= () => import(/* webpackChunkName: "group-panda" */ "./components/panda/panda.vue");
// ...
export const appRoute = [
{
path: "",
name: "root",
redirect: '/index'
},
{
path: "/index",
name: "index",
component: index
},
{
path: "/panda",
name: "panda",
component: panda
},
//...
{
path: "**",
name: "http404",
component: http404
}
];
所以 panda 模块是延迟加载的。但是,当我导航到panda
页面,一个console.log()
of this.$route.path
in App.vue
's mounted()
生命周期仅输出
"/"
代替
"/panda"
但索引页效果很好,它显示准确
"/index"
正如预期的那样。
那么,当页面初始加载时,Vue 路由器如何正确获取延迟加载页面的当前路径呢?我错过了什么?
Edit:
然而,它可以在 Webpack 热重载后捕获正确的路径。它在第一次访问时捕获“/”panda
,但是当我更改源代码中的某些内容后,webpack-dev-server 热重载,然后它会得到“/panda”。
所以我猜这与 Vue 生命周期有关。
有一个currentRoute
对我有用的财产:
this.$router.currentRoute
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)