Vue3中动态组件使用

一,动态组件使用

应用场景:动态绑定或切换组件

应用Vue3碎片: is

1.使用

a.组件A

<div class="layout-base">
 <Button>红茶</Button>
</div>

a.组件B

<div class="layout-base">
 <Button>绿茶</Button>
</div>

2.页面使用

<template>
<div class="layout-base">
     <component :is='isChange? ReaTea:GreenTea'></component>
      <Button @click="showChange">换茶</Button>
</div>
</template>

<script setup>

import {ref} from 'vue'
import GreenTea from'./comisTabs/greenTea.vue'
import RedTea.vue from './comisTabs/redTea.vue'

const isChange=ref(false)
const showChange=(()=>isChange.value=!isChange.value)

</script>

3.效果图

简单使用,总结至此,欢迎各位工友交流学习。

传送门:
1.Vue3中provide,inject使用
2.Vue3中使用自定义指令

相关推荐
GHUIJS5 分钟前
【vue3】vue3.5
前端·javascript·vue.js
-seventy-15 分钟前
对 JavaScript 原型的理解
javascript·原型
&白帝&32 分钟前
uniapp中使用picker-view选择时间
前端·uni-app
谢尔登39 分钟前
Babel
前端·react.js·node.js
ling1s39 分钟前
C#基础(13)结构体
前端·c#
卸任1 小时前
使用高阶组件封装路由拦截逻辑
前端·react.js
lxcw1 小时前
npm ERR! code CERT_HAS_EXPIRED npm ERR! errno CERT_HAS_EXPIRED
前端·npm·node.js
秋沐1 小时前
vue中的slot插槽,彻底搞懂及使用
前端·javascript·vue.js
这个需求建议不做1 小时前
vue3打包配置 vite、router、nginx配置
前端·nginx·vue
QGC二次开发1 小时前
Vue3 : Pinia的性质与作用
前端·javascript·vue.js·typescript·前端框架·vue