美文网首页
使用import(path).then()异步加载虚拟DOM

使用import(path).then()异步加载虚拟DOM

作者: 曾祥辉 | 来源:发表于2021-04-10 18:20 被阅读0次

直接上代码

//父组件
<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>

相关文章

网友评论

      本文标题:使用import(path).then()异步加载虚拟DOM

      本文链接:https://www.haomeiwen.com/subject/udmnkltx.html