defineAsyncComponent只能在H5用,APP端改为使用vite的 import.meta.glob,
注意:import.meta.glob不是vue或uni自带的,是vite的方法,我项目使用了vite;
代码示例:
<template>
<component :is="comp.tb“></component>
</template>
<script>
import { defineAsyncComponent, onMounted, reactive,markRaw } from 'vue'
setup() {
const comp = reactive({})
onMounted(async () => {
const fileModules = import.meta.glob('./tb.vue')
const c = await fileModules['./tb.vue']()
comp.tb = markRaw(c.default)
})
return {
comp
}
}
</script>
本文介绍了如何在从H5项目迁移到使用Vite构建的APP端应用中,替换defineAsyncComponent以实现动态加载组件,特别强调了import.meta.glob在Vite中的作用以及相应的代码示例。

4252

被折叠的 条评论
为什么被折叠?



