色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

vue使用動(dòng)態(tài)組件實(shí)現(xiàn)TAB切換效果完整實(shí)例

瀏覽:226日期:2022-06-09 17:41:46
目錄
  • 一、方法1:使用Vant組件庫(kù)的tab組件
  • 二、 方法2:手動(dòng)創(chuàng)建tab切換效果
  • 三、完整代碼
  • 總結(jié)

一、方法1:使用Vant組件庫(kù)的tab組件

二、 方法2:手動(dòng)創(chuàng)建tab切換效果

1.在components文件夾下創(chuàng)建切換的.vue頁(yè)面、引入使用

import one from "./components/one";import two from "./components/two";import three from "./components/three";import four from "./components/four";components: {    one,    two,    three,    four,},

2.布局:上面放tab點(diǎn)擊的標(biāo)簽,下面放組件呈現(xiàn)對(duì)應(yīng)內(nèi)容

// 然后使用v-for循環(huán)出來(lái)呈現(xiàn)<template>   <div id="app">      <div>      <!-- 放置tab點(diǎn)擊標(biāo)簽 --> <div :class="{ highLight: whichIndex == index }" v-for="(item, index) in cardArr" :key="index" @click="whichIndex = index">    {{ item.componentName }}</div>      </div>      <div><!-- 放置動(dòng)態(tài)組件... -->       <!-- keep-alive緩存組件,這樣的話,組件就不會(huì)被銷毀,DOM就不會(huì)被重新渲染,       瀏覽器也就不會(huì)回流和重繪,就可以優(yōu)化性能。不使用的話頁(yè)面加載就會(huì)慢一點(diǎn) -->       <keep-alive> <component :is="componentId"></component>       </keep-alive>      </div>   </div></template>

3.寫好上面的tab點(diǎn)擊標(biāo)簽,定義數(shù)據(jù)修改樣式

// 首先我們?cè)赿ata中定義數(shù)組cardArr存放點(diǎn)擊tab的數(shù)據(jù)data() {   return {      whichIndex: 0,      cardArr: [{  componentName: "動(dòng)態(tài)組件一",  componentId: "one",},{  componentName: "動(dòng)態(tài)組件二",  componentId: "two",},{  componentName: "動(dòng)態(tài)組件三",  componentId: "three",},{  componentName: "動(dòng)態(tài)組件四",  componentId: "four",},      ],    };},
// 又因?yàn)樾枰懈吡翣顟B(tài)樣式:默認(rèn)索引0高亮.highLight {  box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);  transform: translate3d(0, -1px, 0);}

三、完整代碼

<template>  <div id="app">    <div>      <div       :class="{ highLight: whichIndex == index }"v-for="(item, index) in cardArr":key="index"@click="  whichIndex = index;  componentId = item.componentId;"      >{{ item.componentName }}      </div>    </div>    <div>      <keep-alive><component :is="componentId"></component>      </keep-alive>    </div>  </div></template><script>import one from "./components/one";import two from "./components/two";import three from "./components/three";import four from "./components/four";export default {  components: {    one,    two,    three,    four,  },  data() {    return {      whichIndex: 0,      componentId: "one",      cardArr: [{  componentName: "動(dòng)態(tài)組件一",  componentId: "one",},{  componentName: "動(dòng)態(tài)組件二",  componentId: "two",},{  componentName: "動(dòng)態(tài)組件三",  componentId: "three",},{  componentName: "動(dòng)態(tài)組件四",  componentId: "four",},      ],    };  },};</script><style lang="less" scoped>#app {  width: 100%;  height: 100vh;  box-sizing: border-box;  padding: 50px;  .top {    width: 100%;    height: 80px;    display: flex;    justify-content: space-around;    .crad {      width: 20%;      height: 80px;      line-height: 80px;      text-align: center;      background-color: #fff;      border: 1px solid #e9e9e9;    }    .highLight {      box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);      transform: translate3d(0, -1px, 0);    }  }  .bottom {    margin-top: 20px;    width: 100%;    height: calc(100% - 100px);    border: 3px solid pink;    display: flex;    justify-content: center;    align-items: center;  }}</style>

總結(jié)

到此這篇關(guān)于vue使用動(dòng)態(tài)組件實(shí)現(xiàn)TAB切換效果的文章就介紹到這了,更多相關(guān)vue動(dòng)態(tài)組件實(shí)現(xiàn)TAB切換內(nèi)容請(qǐng)搜索以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持!

標(biāo)簽: JavaScript
相關(guān)文章:
主站蜘蛛池模板: 国内自拍在线观看 | 免费的a级毛片 | 国产成人综合久久精品亚洲 | 亚洲一区二区三区免费看 | 全部在线美女网站免费观看 | 美女的被男人桶爽网站 | 国产一区在线免费观看 | 久久99国产综合精品 | 亚洲综合p| 久久观看| 国产a精品 | 国产免费自拍 | 在线观看免费视频国产 | 成年人在线免费 | 97天天干 | 色综合久久88色综合天天 | 日韩精品一区二区三区视频网 | 日本加勒比在线 | 99re7在线精品免费视频 | 80日本xxxxxxxxx | 亚洲最大网址 | 欧美日韩不卡在线 | 亚洲一级毛片视频 | 欧美综合视频在线观看 | 成人公开免费视频 | 亚洲美女视频一区二区三区 | 国产最爽的乱淫视频国语对 | 天天夜天干天天爽 | 日韩欧美一区二区三区不卡视频 | 巨乳激情| 中文字幕一级 | 亚洲综合99 | 亚洲欧美日韩综合久久久久 | 亚洲精品14p| 国产在线精品一区二区不卡 | 超级香蕉97视频在线观看一区 | 久久久久久久久久久视频国内精品视频 | 波多野结衣中文在线 | 国产亚洲欧洲一区二区三区 | 美女黄色免费看 | 久久久成人啪啪免费网站 |