欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2023年05月13日 10:21:12   作者:魷魚(yú)絲2號(hào)  
在實(shí)際項(xiàng)目開(kāi)發(fā)中,我們經(jīng)常會(huì)遇到選項(xiàng)卡切換,對(duì)于一個(gè)前端工程師來(lái)說(shuō),組件化/模塊化開(kāi)發(fā)是一種必備的行為規(guī)范,下面這篇文章主要給大家介紹了關(guān)于vue使用動(dòng)態(tài)組件實(shí)現(xiàn)TAB切換效果的相關(guān)資料,需要的朋友可以參考下

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

Vant 2 - Mobile UI Components built on Vue

二、 方法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 class="top">
      <!-- 放置tab點(diǎn)擊標(biāo)簽 -->
         <div class="crad"
         :class="{ highLight: whichIndex == index }"
         v-for="(item, index) in cardArr"
         :key="index"
         @click="whichIndex = index">
            {{ item.componentName }}
        </div>
      </div>
      <div class="bottom">
        <!-- 放置動(dòng)態(tài)組件... -->
       <!-- keep-alive緩存組件,這樣的話(huà),組件就不會(huì)被銷(xiāo)毀,DOM就不會(huì)被重新渲染,
       瀏覽器也就不會(huì)回流和重繪,就可以?xún)?yōu)化性能。不使用的話(huà)頁(yè)面加載就會(huì)慢一點(diǎn) -->
       <keep-alive>
         <component :is="componentId"></component>
       </keep-alive>
      </div>
   </div>
</template>

3.寫(xiě)好上面的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 class="top">
      <div
        class="crad"
        :class="{ highLight: whichIndex == index }"
        v-for="(item, index) in cardArr"
        :key="index"
        @click="
          whichIndex = index;
          componentId = item.componentId;
        "
      >
        {{ item.componentName }}
      </div>
    </div>
    <div class="bottom">
      <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)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue使用window.open()跳轉(zhuǎn)頁(yè)面的代碼案例

    vue使用window.open()跳轉(zhuǎn)頁(yè)面的代碼案例

    這篇文章主要介紹了vue中對(duì)window.openner的使用,vue使用window.open()跳轉(zhuǎn)頁(yè)面的代碼案例,本文通過(guò)實(shí)例代碼給大家詳細(xì)講解,需要的朋友可以參考下
    2022-11-11
  • Element UI框架中巧用樹(shù)選擇器的實(shí)現(xiàn)

    Element UI框架中巧用樹(shù)選擇器的實(shí)現(xiàn)

    這篇文章主要介紹了Element UI框架中巧用樹(shù)選擇器的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12
  • laravel5.4+vue+element簡(jiǎn)單搭建的示例代碼

    laravel5.4+vue+element簡(jiǎn)單搭建的示例代碼

    本篇文章主要介紹了laravel5.4+vue+element簡(jiǎn)單搭建的示例代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • vue-lazyload使用總結(jié)(推薦)

    vue-lazyload使用總結(jié)(推薦)

    vue項(xiàng)目用到vue-lazyload做圖片懶加載,這篇文章主要介紹了vue-lazyload使用總結(jié),解決這個(gè)插件的坑,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2018-11-11
  • vue3封裝京東商品詳情頁(yè)放大鏡效果組件

    vue3封裝京東商品詳情頁(yè)放大鏡效果組件

    這篇文章主要為大家詳細(xì)介紹了vue3封裝類(lèi)似京東商品詳情頁(yè)放大鏡效果組件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Vue-Access-Control 前端用戶(hù)權(quán)限控制解決方案

    Vue-Access-Control 前端用戶(hù)權(quán)限控制解決方案

    Vue-Access-Control是一套基于Vue/Vue-Router/axios 實(shí)現(xiàn)的前端用戶(hù)權(quán)限控制解決方案。這篇文章主要介紹了Vue-Access-Control:前端用戶(hù)權(quán)限控制解決方案,需要的朋友可以參考下
    2017-12-12
  • 詳解vue通過(guò)NGINX部署在子目錄或者二級(jí)目錄實(shí)踐

    詳解vue通過(guò)NGINX部署在子目錄或者二級(jí)目錄實(shí)踐

    這篇文章主要介紹了詳解vue通過(guò)NGINX部署在子目錄或者二級(jí)目錄實(shí)踐,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09
  • vue 利用路由守衛(wèi)判斷是否登錄的方法

    vue 利用路由守衛(wèi)判斷是否登錄的方法

    今天小編就為大家分享一篇vue 利用路由守衛(wèi)判斷是否登錄的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-09-09
  • 仿vue-cli搭建屬于自己的腳手架的方法步驟

    仿vue-cli搭建屬于自己的腳手架的方法步驟

    這篇文章主要介紹了仿vue-cli搭建屬于自己的腳手架的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • 詳解vue+css3做交互特效的方法

    詳解vue+css3做交互特效的方法

    本篇文章主要介紹了詳解vue+css3做交互特效的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-11-11

最新評(píng)論