动态路由 出现 for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.

发布时间 2023-05-28 10:51:54作者: 小庄的blog

for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.

Plugin: vite:import-analysis

如果不是vite,用以前的webpack,只需要 ()=> import(‘XXX’) 只能成功导入动态路由,且可以使用别名(前提你配置了别名)。如果是vite不能使用别名,你需要加 “../”相当路由的方式

但它会提示警告,你当然可以用上面的 /* @vite-ignore */  方式取消这个警告,但如果想要vite方式,就不会有这个警告,请看下面:

 官网已经说了:https://cn.vitejs.dev/guide/features.html#glob-import

(感觉有点脱裤子放屁,最终还是() => import('xxx')方式) 

好,那我们可以就可以这样做。

1)引入 :(注意:** 表示多级目录,如果只是*只是一级目录 )

const modules = import.meta.glob('../views/**/*.vue')
2)然后: