- 如果使用动态路由,import不能使用变量,如:
component: () => {
import(`@/${e.component}`)
}
这样引用会报引用失败的错误:
vue-router.esm.js?8c4f:1921 Error: Cannot find module '@/views/app/index'
at webpackEmptyContext (eval at ./src/views/app/index sync recursive (app.js:2800), <anonymous>:2:10)
at eval (routes.js?092f:10)
- 解决, 改成如下代码
component: (resolve) => require([`@/${e.component}`], resolve),
网友评论