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中使用自定义指令
在这里插入图片描述

相关推荐

  1. Vue3使用动态组件

    2024-01-20 07:58:03       68 阅读
  2. 详解Vue3如何使用动态组件

    2024-01-20 07:58:03       23 阅读
  3. Vue3使用component动态展示组件

    2024-01-20 07:58:03       39 阅读
  4. i18n在VUE3使用插槽动态传入组件

    2024-01-20 07:58:03       35 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-20 07:58:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-20 07:58:03       101 阅读
  3. 在Django里面运行非项目文件

    2024-01-20 07:58:03       82 阅读
  4. Python语言-面向对象

    2024-01-20 07:58:03       91 阅读

热门阅读

  1. 服务器工作环境要求

    2024-01-20 07:58:03       54 阅读
  2. 【温故而知新】HTML5 应用程序缓存

    2024-01-20 07:58:03       56 阅读
  3. openssl3.2 - 官方demo学习 - pkey - EVP_PKEY_DSA_paramgen.c

    2024-01-20 07:58:03       55 阅读
  4. webpack

    2024-01-20 07:58:03       42 阅读
  5. 利用Facebook广告进行品牌宣传的优缺点有哪些

    2024-01-20 07:58:03       60 阅读
  6. Stable Diffusion中不同的采样方法

    2024-01-20 07:58:03       49 阅读
  7. 爬虫(学习笔记)

    2024-01-20 07:58:03       54 阅读
  8. 1.6 面试经典150题 - 跳跃游戏

    2024-01-20 07:58:03       63 阅读