当前位置:网站首页>5.component动态组件的展示
5.component动态组件的展示
2022-07-27 04:00:00 【道长道长IOT】
话不多说,直接展示所有代码,具体注释都在内容里面,开箱即用
<template>
<div class="container">
<span :class="checked === item.id ? 'active' : ''" v-for="(item, index) in btnList" :key="item.id" @click="changeTabs(item)">{
{ item.name }}</span>
<div>
<!-- 这里是动态切换组件的属性名称 -->
<component :is="current.Name"></component>
</div>
</div>
</template>
<script setup> import {
reactive, ref, markRaw } from 'vue' import A from '@/components/canChangeCom/comA.vue' import B from '@/components/canChangeCom/comB.vue' import C from '@/components/canChangeCom/comC.vue' // 动态组件的数据 // 这里为什么使用markRaw markRaw可以取消数据的proxy代理 const btnList = reactive([ {
id: 1, name: 'A' , comName: markRaw(A)}, {
id: 2, name: 'B' , comName: markRaw(B)}, {
id: 3, name: 'C' , comName: markRaw(C)}, ]) // 他们不存在变量提升,当我下面的数据需要使用上面数据的时候,我必须在把数据生命在下方 // 设置默认展示的组件 let current = reactive({
Name: btnList[0].comName }) // 这里是默认选中的按钮,默认让他为第一个 let checked = ref(1) const changeTabs = (item) => {
// 高亮选中的按钮 checked.value = item.id // 当前显示的组件 current.Name = item.comName } </script>
<style lang="scss" scoped> .container {
width: 100%; height: 500px; border: 3px solid #ccc; span {
display: inline-block; width: 100PX; border: 1px solid #ccc; text-align: center; margin-left: 10px; margin-top: 10px; cursor: pointer; } .active {
background: orange; } } </style>
边栏推荐
- 好用的shell快捷键
- 微信小程序轮播图
- Unity:Resource Merging、Static Batching、Dynamic Batching、GPU Instancing
- pinia的持久化存储,pinia使用插件进行持久化存储。
- Network knowledge corner | it only takes four steps to teach you to use SecureCRT to connect to ENSP. You must see the operation guide of common tools
- JMeter学习笔记004-CSV文件行数控制循环次数
- State Hook
- Overview of communication protocols
- shell编程增强
- Convolution neural network -- a detailed introduction to convolution of 24 bit color images
猜你喜欢

通信协议综述
![[machine learning network] BP neural network and deep learning-6 deep neural networks (DNN)](/img/6a/02c76f5bd35b2d89e4f471b9b688f5.png)
[machine learning network] BP neural network and deep learning-6 deep neural networks (DNN)

Brightcove任命Dan Freund为首席营收官

JS modify the key value of the object array

结构型模式-适配器模式

Elastic open source community: Developer Recruitment

微信小程序轮播图

Prometheus Node Exporter 常用监控指标

JMeter学习笔记004-CSV文件行数控制循环次数

shel自动设置目录权限
随机推荐
电商分账系统重要吗,平台应该如何选择分账服务商呢?
State Hook
How CentOS installs mysqldump
[machine learning network] BP neural network and deep learning-6 deep neural networks (DNN)
P1438 无聊的数列 线段树+差分
EVT interface definition file of spicy
好用移动APP自动化测试框架哪里找?收藏这份清单就好了!
spicy之evt接口定义文件
redux三大核心
标准C语言13
[C language] recursively explain the tower of Hanoi problem
[leetcode] day104 no overlapping interval
【无标题】
HEAD detached from origin/...导致push失败
第六章:云数据库
管理信息系统期末复习
Preliminary understanding of NiO
Anonymous named pipes, understanding and use of interprocess communication in shared memory
第二轮Okaleido Tiger即将登录Binance NFT,或持续创造销售神绩
How to set user-defined display for Jiaming Watch