国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Vue.js組件實現選項卡以及切換特效

2024-05-06 15:36:41
字體:
來源:轉載
供稿:網友

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

最近在學習Vue,當看梁灝大神寫的《Vue.js實戰》時看到了關于用組件實現選項卡功能,我也根據課后的練習加上自己的理解重新編寫了一下。

組件分為pane.js和tabs.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自帶封裝的,不懂的同學可以去找文檔,主要是可以實現動畫   <transition name="slide-fade">     <pane label="標簽一" name="1">     標簽一的內容    </pane>   </transition>   <transition name="slide-fade">    <pane label=" 標簽二" name="2">     標簽二的內容    </pane>   </transition>   <transition name="slide-fade">    <pane label="標簽三" name="3">     標簽三的內容    </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.jsVue.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()"> 關閉/打開 </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();  }, },});            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 西乌珠穆沁旗| 搜索| 淮安市| 额敏县| 德令哈市| 永新县| 宁陕县| 商洛市| 西城区| 吕梁市| 淳安县| 霍林郭勒市| 怀集县| 楚雄市| 安顺市| 湖口县| 汾阳市| 三穗县| 施秉县| 京山县| 渭南市| 甘南县| 内江市| 屯门区| 霍州市| 阳新县| 综艺| 平昌县| 仙桃市| 凤冈县| 万安县| 珠海市| 嘉兴市| 吉林省| 虎林市| 策勒县| 台东市| 蚌埠市| 抚远县| 许昌市| 乃东县|