直接上代码
//父组件
<template>
<Componet path="@/componet/Componet.vue ">
</Componet >
</template>
.......
//子组件
<template>
<article v-html="content">
</article>
</template>
<script lang="ts">
import { ref } from "vue";
export default {
props: {
path: {
type: String,
required: true,
},
},
setup(props) {
const content = ref<string>(null);
// 异步引入组件
import(props.path).then((res) => {
// 使用console.log({...res})打印发现虚拟节点在default
content.value = res.default;
});
return {
content,
};
},
};
</script>