vite-ts-quick icon indicating copy to clipboard operation
vite-ts-quick copied to clipboard

打包后路由有问题

Open youfak opened this issue 2 years ago • 1 comments

打包后会出现“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 }
}

youfak avatar Jun 13 '22 02:06 youfak

这应该是版本更新所导致的?之前没遇到过这个问题

orziz avatar Jul 19 '22 15:07 orziz

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: @.***>

youfak avatar Sep 09 '22 03:09 youfak

看到啦,我删了,刚没注意

orziz avatar Sep 09 '22 04:09 orziz