Vue3 动态加载组件
ts
<script lang="ts" setup>
import { defineAsyncComponent} from 'vue'
import predefine from "./predefine";
const props = defineProps(predefine)
const bean=defineAsyncComponent(() => import(`./${props.component}.vue`))
</script>
<template>
<div>
<bean v-bind="props"/>
</div>
</template>
<script lang="ts" setup>
import { defineAsyncComponent} from 'vue'
import predefine from "./predefine";
const props = defineProps(predefine)
const bean=defineAsyncComponent(() => import(`./${props.component}.vue`))
</script>
<template>
<div>
<bean v-bind="props"/>
</div>
</template>
小节
核心就是利用defineAsyncComponent
来动态加载远程的组件
用内置的component也可以
html
<component :is="bean" v-bind="props"></component>
<component :is="bean" v-bind="props"></component>