使用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>
网友评论