vue3+vite,写动态路由时候遇到的坑

import导入一直报错,看了网上说import不行要写成 require之类的,都试了个遍,结果还是不行。

一个很容易犯的错误:理所当然的以为alias是可以使用的。

事实上写全相对路径就可以了!!!

 

let r = await apis['common/getRouteList']()
const list = r.map((t) => ({
id: t.id,
pid: t.parentId,
name: t.name,
path: t.path,
meta: {
title: t.title,
icon: t.icon,
type: t.type,
},
//正确写法 import(`/src/views${t.component}`)
//错误写法 import(`@/views${t.component}`)
component: () => import(`/src/views${t.component}`)
}));

还是基础不行,忽略了vite的alias

posted @ 2024-05-17 18:57  marisen  阅读(47)  评论(0编辑  收藏  举报