错误信息
Cannot find module '@/views/login/index'
Failed to resolve async component default
vue-router.esm.js:1897 Error: Cannot find module '@/views/login/index'
at webpackEmptyContext (index.js:39)
at permission.js:90
解决方法
进入router中的index.js
component: () => import('@/views/login/index'),
改为
component: (resolve) => require(["@/views/login/index"], resolve),
如果是动态路由则
export const loadView = (view) => { // 路由懒加载
return () => import(`@/views/${view}`)
}
改为
export const loadView = (view) => { // 路由懒加载
return (resolve) => require([`@/views/${view}`], resolve)
}
错误原因是老外修改了webpack打包逻辑,webpack4中动态import不支持变量方式,
该修改对于生产环境无影响,只在开发环境有问题
如果解决了你的问题,请回来点赞哦。