joken-前端工程师

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: :: :: 管理 ::
  394 随笔 :: 39 文章 :: 8 评论 :: 20万 阅读

使用方式

父组件

<template>
  <div class="box">
    <div>
      <!-- setup需要用变量的方式来写入is,如果是options api方式可以用组件字符 -->
       <!-- myProps 属性可以直接传到动态组件 -->
      <component :is="childT" myProps="sldfjsklfjksfjsfj"/>
    </div>
  </div>
</template>
<script lang="ts" setup>

import childT from "./components/childT.vue";


</script>
<style lang="stylus" scoped></style>


子组件:childT.vue

<template>
  <div class='box'>
    childT
  </div>
</template>
<script lang='ts' setup>
// import { ref, reactive, computed, onMounted, nextTick } from 'vue';


const props = defineProps<{
  myProps: string,
}>();

console.log(props.myProps,"ldsnvlsdjfskdjfsfdj");
</script>
<style lang='scss' scoped></style>

tsx如何component is

参考:

import { defineComponent } from 'vue';
import ChildT from './components/ChildT';
import { h } from 'vue';

const App = defineComponent({
  setup() {
    return () => (
      <div class="box">
        <div>
          {h(ChildT, { myProps: "sldfjsklfjksfjsfj" })}
        </div>
      </div>
    );
  }
});

export default App;

也就是使用h函数,动态渲染组件

posted on   joken1310  阅读(454)  评论(2编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示