vite-ts-quick
vite-ts-quick copied to clipboard
打包后路由有问题
打包后会出现“Error: Unknown variable dynamic import :”的问题
/** 以下代码不要修改 */
function loadRouters() {
const context = import.meta.globEager("../views/**/*.vue");
const routes: RouteRecordRaw[] = [];
Object.keys(context).forEach((key: any) => {
if (key === "./index.ts") return;
let name = key.replace(/(\.\.\/views\/|\.vue)/g, '');
let path = "/" + name.toLowerCase();
if (name === "Index") path = "/";
routes.push({
path: path,
name: name,
component: () => import(`../views/${name}.vue`)
})
});
return { context, routes }
}
需要更改为如下
/** 以下代码不要修改 */
function loadRouters() {
const context = import.meta.globEager("../views/**/*.vue");
const routes: RouteRecordRaw[] = [];
Object.keys(context).forEach((key: any) => {
if (key === "./index.ts") return;
let name = key.replace(/(\.\.\/views\/|\.vue)/g, '');
let path = "/" + name.toLowerCase();
if (name === "Index") path = "/";
routes.push({
path: path,
name: name,
component: () => context[`../views/${name}.vue`]
})
});
return { context, routes }
}
这应该是版本更新所导致的?之前没遇到过这个问题
Import 换了 context 啊
从 Windows 版邮件https://go.microsoft.com/fwlink/?LinkId=550986发送
发件人: @.> 发送时间: 2022年9月9日 11:57 收件人: @.> 抄送: @.>; @.> 主题: Re: [pohunchn/vite-ts-quick] 打包后路由有问题 (Issue #8)
你这代码也没改啊……
― Reply to this email directly, view it on GitHubhttps://github.com/pohunchn/vite-ts-quick/issues/8#issuecomment-1241469916, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AGPBVOGK3G54R3ZEFME5HQDV5KYT3ANCNFSM5YSXRSUA. You are receiving this because you authored the thread.Message ID: @.***>
看到啦,我删了,刚没注意