随笔 - 115  文章 - 0  评论 - 0  阅读 - 40316

16:vue3 动态组件

A组件

1 <template>
2     <h3>ComponentA</h3>
3 </template>

B组件

1 <template>
2     <h3>ComponentB</h3>
3 </template>

 

App.vue

复制代码
 1 <template>
 2   <h3>动态组件(A、B两个组件动态切换)</h3>
 3   <component :is="tabComponent"></component>
 4   <button @click="changeHandle">切换组件</button>
 5 </template>
 6 
 7 <script>
 8 import ComponentA from "./components/ComponentA.vue"
 9 import ComponentB from "./components/ComponentB.vue"
10 
11 export default{
12     data(){
13       return{
14         tabComponent:"ComponentA"
15       }
16     },
17     methods:{
18       changeHandle(){
19         this.tabComponent=this.tabComponent=="ComponentA"?"ComponentB":"ComponentA"
20       }
21    },
22    components:{
23     ComponentA,
24     ComponentB
25    }
26     
27 }
28 </script>
复制代码

 

posted on   wuzx-blog  阅读(86)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示