美文网首页
vue3动态组件defineComponent

vue3动态组件defineComponent

作者: yichen_china | 来源:发表于2023-08-31 14:18 被阅读0次

使用defineComponent 创建动态组件
官方文档 https://cn.vuejs.org/guide/extras/render-function.html#v-if

<script setup>
import {defineComponent,  h} from 'vue';
const ok=true
const Childer = defineComponent({
  props: {
      ok:{
      type:Boolean,
      },
    tag: {
      type: String,
      required: true
    },
    childKey: {
      type: String,
      required: true
    },
    conf: {
      type: Object,
      required: true
    }
  },
  setup(props,{attrs}) {
    console.log("tag")
    return () =>h('div', [ok ? h('button', 'yes') : h('span', 'no')]);
  },
});
</script>

<template>
    <h1>Here are many child components!</h1>
    <Childer/>
</template>

相关文章

网友评论

      本文标题:vue3动态组件defineComponent

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