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

Vue.js組件實現(xiàn)選項卡以及切換特效

 更新時間:2019年07月24日 09:49:17   作者:逐魚  
這篇文章主要為大家詳細介紹了Vue.js組件實現(xiàn)選項卡以及切換特效,具有一定的參考價值,感興趣的小伙伴們可以參考一下

Vue.js組件實現(xiàn)選項卡以及切換動畫特效,供大家參考,具體內(nèi)容如下

最近在學(xué)習(xí)Vue,當(dāng)看梁灝大神寫的《Vue.js實戰(zhàn)》時看到了關(guān)于用組件實現(xiàn)選項卡功能,我也根據(jù)課后的練習(xí)加上自己的理解重新編寫了一下。

組件分為pane.jstabs.js兩個部分,話不多說,直接上代碼。

<!DOCTYPE html>
<html lang="en">

<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <meta http-equiv="X-UA-Compatible" content="ie=edge">
 <link rel="stylesheet" href="style.css" rel="external nofollow" >
 <title>Document</title>
</head>

<body>
 <div id="app">
  <tabs v-model="activeKey">
   //transiton是Vue自帶封裝的,不懂的同學(xué)可以去找文檔,主要是可以實現(xiàn)動畫
   <transition name="slide-fade"> 
    <pane label="標(biāo)簽一" name="1">
     標(biāo)簽一的內(nèi)容
    </pane>
   </transition>
   <transition name="slide-fade">
    <pane label=" 標(biāo)簽二" name="2">
     標(biāo)簽二的內(nèi)容
    </pane>
   </transition>
   <transition name="slide-fade">
    <pane label="標(biāo)簽三" name="3">
     標(biāo)簽三的內(nèi)容
    </pane>
   </transition>

  </tabs>
 </div>


 <script src="vue/vue.js"></script>
 <script src="pane.js"></script>
 <script src="tabs.js"></script>
 <script src="text.js"></script>
</body>

</html>
//tabs.js
Vue.component('tabs', {
 template: `
 <div class="tabs">
  <div class="tabs-bar">
  <div :class="tabCls(item)" v-for="(item, index) in navList" @click="handleChange(index)">
   {{item.label}}
  </div>
  <button @click="removePane()"> 關(guān)閉/打開 </button>
  </div>

  <div class="tabs-content">
    <slot></slot> 
  </div>
 </div>
 `,
 props: {
  value: {
   type: [String, Number],
  },
 },
 data: function () {
  return {
   currentValue: this.value,
   navList: [],
  };
 },
 methods: {
  tabCls: function (item) {
   return [
    'tabs-tab',
    {
     'tabs-tab-active': item.name === this.currentValue,
    },
   ];
  },
  getTabs() {
   return this.$children.filter(function (item) {
    return item.$options.name === 'pane';
   });
  },
  updateNav() {
   this.navList = [];
   var _this = this;

   this.getTabs().forEach(function (pane, index) {
    _this.navList.push({
     label: pane.label,
     name: pane.name || index,
     bool: pane.closable,
    });
    if (!pane.name) pane.name = index;
    if (index === 0) {
     if (!_this.currentValue) {
      _this.currentValue = pane.name || index;
     }
    }
   });
   this.updateStatus();
  },
  updateStatus() {
   var tabs = this.getTabs();
   var _this = this;
   tabs.forEach(function (tab) {
    return (tab.show = tab.name === _this.currentValue);
   });
  },
  handleChange: function (index) {
   var nav = this.navList[index];
   var name = nav.name;

   this.currentValue = name;
   this.$emit('input', name);
   // this.$emit('on-click', name);
  },
  removePane: function () {
   var bool = this.navList[1].bool;
   console.log(bool);
   if (bool) {
    this.navList[1].bool = false;
    this.currentValue = '0';
   }
   if (!bool) {
    this.navList[1].bool = true;
    this.currentValue = '1';
    this.$emit('input', '1');
   }
  },
 },
 watch: {
  value: function (val) {
   this.currentValue = val;
  },
  currentValue: function () {
   console.log('demo');
   this.updateStatus();
  },
 },
});
//pane.js
Vue.component('pane', {
 name: 'pane',
 template: `
 <div class="pane" v-if="show">
  <slot> </slot>
 </div>
 `,
 props: {
  name: {
   type: String
  },
  label: {
   type: String,
   default: ''
  },
  closable: {
   type: Boolean,
   default: true
  }
 },

 data: function () {
  return {
   show: true
  }
 },
 methods: {
  updateNav() {
   this.$parent.updateNav();
  }
 },
 watch: {
  label() {
   this.updateNav();
  }
 },
 mounted() {
  this.updateNav();
 }
})
//style.css
.tabs {
 font-size: 14px;
 color: black;
}

.tabs-bar:after {
 content: '';
 display: block;
 width: 100%;
 height: 1px;
 position: relative;
 background: rgba(78, 81, 128, 0.5);
}

.tabs-tab {
 display: inline-block;
 padding: 4px 16px;
 margin-right: 6px;
 color: rgba(0, 0, 0, 0.6);
 background: rgba(134, 134, 131, 0.137);
 border: 1px solid rgba(154, 214, 248, 0.856);
 cursor: pointer;
 position: relative;
}

.tabs-tab-active {
 background: rgb(252, 251, 251);
 color: rgba(0, 0, 0, 1);
 border-top: 1px solid rgba(154, 214, 248, 0.856);
 border-bottom: 1px solid white;
}

/* .tabs-tab-active:before {
 content: '';
 display: block;
 height: 5px;
 background: grey;
 position: absolute;
 top: 0;
 left: 0;
 right: 0;
} */

.tabs-content {
 position: relative;
 left: 10px;
 top: 30px;
 padding: 8px 0;
}

/* 可以設(shè)置不同的進入和離開動畫 */
/* 設(shè)置持續(xù)時間和動畫函數(shù) */
.slide-fade-enter-active {
 transition: all 1.3s ease;
}

.slide-fade-leave-active {
 transition: all 1.8s cubic-bezier(1, 0.5, 0.8, 1);
}

.slide-fade-enter,
.slide-fade-leave-to

/* .slide-fade-leave-active for below version 2.1.8 */
 {
 transform: translateY(30px);
 opacity: 0;
}
//text.js
var app = new Vue({
 el: '#app',
 data: {
  activeKey: '1',
 },
})

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue中使用Openlayer實現(xiàn)加載動畫效果

    Vue中使用Openlayer實現(xiàn)加載動畫效果

    這篇文章主要介紹了Vue+Openlayer加載動畫效果的實現(xiàn)代碼,代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2021-08-08
  • vuejs+element UI點擊編輯表格某一行時獲取內(nèi)容填入表單的示例

    vuejs+element UI點擊編輯表格某一行時獲取內(nèi)容填入表單的示例

    這篇文章主要介紹了vuejs+element UI點擊編輯表格某一行時獲取內(nèi)容填入表單的示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • Vue子組件向父組件傳值示范方法

    Vue子組件向父組件傳值示范方法

    這篇文章主要介紹了Vue子組件向父組件傳值方法,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2023-03-03
  • 基于 Vue 的樹形選擇組件的示例代碼

    基于 Vue 的樹形選擇組件的示例代碼

    本篇文章主要介紹了基于 Vue 的樹形選擇組件的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • vue中計算屬性和方法的區(qū)別及說明

    vue中計算屬性和方法的區(qū)別及說明

    這篇文章主要介紹了vue中計算屬性和方法的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • Vue3 源碼導(dǎo)讀(推薦)

    Vue3 源碼導(dǎo)讀(推薦)

    這篇文章主要介紹了Vue3 源碼導(dǎo)讀(推薦),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • 使用vue/cli出現(xiàn)defineConfig?is?not?function錯誤解決辦法

    使用vue/cli出現(xiàn)defineConfig?is?not?function錯誤解決辦法

    這篇文章主要給大家介紹了關(guān)于使用vue/cli出現(xiàn)defineConfig?is?not?function錯誤的解決辦法,當(dāng)我們在做打包配置的時候,出現(xiàn)了這個錯誤,需要的朋友可以參考下
    2023-11-11
  • Vue路由傳參的三種方式實例詳解

    Vue路由傳參的三種方式實例詳解

    vue路由傳參的使用場景一般都是應(yīng)用在父路由跳轉(zhuǎn)到子路由時,攜帶參數(shù)跳轉(zhuǎn),下面這篇文章主要給大家介紹了關(guān)于Vue路由傳參的三種方式,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2023-01-01
  • Vue js with語句原理及用法解析

    Vue js with語句原理及用法解析

    這篇文章主要介紹了Vue js with語句原理及用法解析,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-09-09
  • VUE+axios+php實現(xiàn)圖片上傳

    VUE+axios+php實現(xiàn)圖片上傳

    這篇文章主要為大家詳細介紹了VUE+axios+php實現(xiàn)圖片上傳,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08

最新評論