//以动态导入路由为例
const path = '@/views/StandardList.vue';
router.addRoute({
path: '/example/blank/blank',
name: 'StandardList',
component: () => import(path),
});
此时该路由的导入其实是无效的,一定会有bug的.
正确的语法:
//以动态导入路由为例
const path = 'views/StandardList'; //这里有改变
router.addRoute({
path: '/example/blank/blank',
name: 'StandardList',
component: () => import(`@/${path}.vue`), //这里有改变
});
动态拼接的异步导入总结:
1.最好使用字符串模板.
2.需要保留别名前缀和写死的后缀名,仅中间部分,可以写活.