vue import 路由使用变量问题

  1. 如果使用动态路由,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)
  1. 解决, 改成如下代码
component: (resolve) => require([`@/${e.component}`], resolve),
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容