关于vue3:关于vue异步加载组件动态路由加载组件的问题

3次阅读

共计 685 个字符,预计需要花费 2 分钟才能阅读完成。

目前应用 vite 搭建后盾管理系统,遇到了异步加载路由组件的问题,加上之前 vue2 的时候异步加载路由组件一起做个整顿,之前做过 vue2, 所以 vue2 和 vue2 一起做个整顿,先说 vue3。

以后应用 vue3 创立动静组件路由办法

const dynamicRoutes = [
   {
        ...,
        component: () => import('@/views/xx.vue')
    }
]

但通常的话后端会返回组件的地址,import 里就会传个动静值,值为组件门路,但应用 vite&vue3 搭建的话会有告警

component: () => import(obj.componentPath)
The above dynamic import cannot be analyzed by Vite.
See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations 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.

网上搜了 vue3+vite 有两种计划

  1. 应用 vue3 的 API defineAsyncComponent 加上正文 / @vite-ignore /
  2. 应用 import.meta.glob 这种办法尝试后失败,就没深入研究
  3. shadowRef 和 defineAsyncComponent 配合应用,还没尝试
正文完
 0