VUE3+vite动态路由配置报错

报错

配置完成后点击菜单控制台报错

generateRoutes.ts:16 Uncaught (in promise) TypeError: Failed to resolve module specifier

输出路由也报错

arguments: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter (<anonymous>:3:28)]

caller: [Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.invokeGetter (<anonymous>:3:28)]

component: () => import(/* @vite-ignore */`@${router.component}`)

在vue3中使用当前配置会不被识别,报错如上

正确语法

使用vite中的语法利用 import.meta.glob 来进行路由获取与匹配

const modules = import.meta.glob('@/views/**/*.vue')

 在此处不能使用 @ 符,使用 @ 符不知道为什么不能被识别,通过 /src + 后端返回的 component 中的数据将路径拼凑出来,这样就可以完成动态引入啦

component: modules[`/src${router.component}`]

config有配置src。如果有大佬知道这里不能使用 @ 的原因求指点一下,谢谢

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值