【发布时间】:2020-05-07 09:42:58
【问题描述】:
我正在使用 npm run serve 运行一个 vue 应用程序。 我正在将组件异步注入到路由中,并且在我看来正在发生一些奇怪的事情,因为当我什至不在该路径上时,它会向我显示有关另一个路径的组件的错误,说该文件丢失了......而且它是是的,它不见了……但是当我在那条路上时,这不是应该被注入的吗?看起来组件已经导入了...
const router = new VueRouter({
routes: [
{ path: '/login', component: () => import('./pages/login.vue') },
{ path: '/register', component: () => import('./pages/register.vue') },
]
我在编译器中看到了这个错误
./src/main.js
Module not found: Error: Can't resolve './pages/register.vue' in '/home/daniel/work/someapp/frontend/src'
并且路径是/login,当然当我创建注册页面时一切正常......只是不明白为什么在尚未加载路由时它会被导入。
【问题讨论】:
-
使用 import('./components/pages/register.vue') 试试
-
如果我创建文件,它会被正确导入......为什么当我根本不在那个路线时它会导入它/检查它......这是我的问题
标签: vue.js vue-router eslint async-components