最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

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

組件分為pane.jstabs.js兩個(gè)部分,話不多說(shuō),直接上代碼。

<!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é)可以去找文檔,主要是可以實(shí)現(xiàn)動(dòng)畫(huà)
   <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)閉/打開(kāi) </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è)置不同的進(jìn)入和離開(kāi)動(dòng)畫(huà) */
/* 設(shè)置持續(xù)時(shí)間和動(dòng)畫(huà)函數(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',
 },
})

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

相關(guān)文章

  • 詳解vue組件之間相互傳值的方式

    詳解vue組件之間相互傳值的方式

    這篇文章主要介紹了vue組件之間相互傳值的方式,對(duì)vue感興趣的同學(xué),可以參考下
    2021-05-05
  • vue-cli結(jié)合Element-ui基于cropper.js封裝vue實(shí)現(xiàn)圖片裁剪組件功能

    vue-cli結(jié)合Element-ui基于cropper.js封裝vue實(shí)現(xiàn)圖片裁剪組件功能

    這篇文章主要介紹了vue-cli結(jié)合Element-ui基于cropper.js封裝vue實(shí)現(xiàn)圖片裁剪組件功能,本文圖文并茂給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2018-03-03
  • Vue的自定義組件不能使用click方法的解決

    Vue的自定義組件不能使用click方法的解決

    這篇文章主要介紹了Vue的自定義組件不能使用click方法的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-07-07
  • 如何為vue的項(xiàng)目添加單元測(cè)試

    如何為vue的項(xiàng)目添加單元測(cè)試

    這篇文章主要介紹了如何為vue的項(xiàng)目添加單元測(cè)試,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12
  • Vue3中操作dom的四種方式總結(jié)(建議收藏!)

    Vue3中操作dom的四種方式總結(jié)(建議收藏!)

    VUE是通過(guò)傳遞一些配置給Vue對(duì)象和頁(yè)面中引用插值表達(dá)式來(lái)操作DOM的,下面這篇文章主要給大家介紹了關(guān)于Vue3中操作dom的四種方式總結(jié),文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-12-12
  • 基于elementUI實(shí)現(xiàn)圖片預(yù)覽組件的示例代碼

    基于elementUI實(shí)現(xiàn)圖片預(yù)覽組件的示例代碼

    這篇文章主要介紹了基于elementUI實(shí)現(xiàn)圖片預(yù)覽組件的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • SpringBoot實(shí)現(xiàn)全局和局部跨域的兩種方式

    SpringBoot實(shí)現(xiàn)全局和局部跨域的兩種方式

    本文主要介紹了SpringBoot實(shí)現(xiàn)全局和局部跨域的兩種方式,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2023-01-01
  • 基于vue實(shí)現(xiàn)分頁(yè)效果

    基于vue實(shí)現(xiàn)分頁(yè)效果

    這篇文章主要介紹了基于vue實(shí)現(xiàn)分頁(yè)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • VSCode中書(shū)寫(xiě)Vue無(wú)代碼提示該如何解決

    VSCode中書(shū)寫(xiě)Vue無(wú)代碼提示該如何解決

    vscode開(kāi)發(fā)vue非常好用,因?yàn)橛泻芏嗟牟寮?可以補(bǔ)全語(yǔ)法,或者高亮便于檢查錯(cuò)誤,但我最近發(fā)現(xiàn)我的vscode卻沒(méi)有了代碼提示,這篇文章主要給大家介紹了關(guān)于VSCode中書(shū)寫(xiě)Vue無(wú)代碼提示該如何解決的相關(guān)資料,需要的朋友可以參考下
    2022-12-12
  • 在vue中路由使用this.$router.go(-1)返回兩次問(wèn)題

    在vue中路由使用this.$router.go(-1)返回兩次問(wèn)題

    這篇文章主要介紹了在vue中路由使用this.$router.go(-1)返回兩次問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12

最新評(píng)論

庄浪县| 喀什市| 金门县| 东乡族自治县| 华安县| 嘉禾县| 马鞍山市| 津市市| 达日县| 五台县| 洛隆县| 浪卡子县| 海南省| 泽州县| 固阳县| 宜昌市| 美姑县| 崇州市| 丰原市| 阜新市| 绿春县| 夏津县| 上高县| 洞口县| 贵溪市| 孟津县| 子长县| 安化县| 成都市| 剑阁县| 内乡县| 道孚县| 陇川县| 桓仁| 铅山县| 长垣县| 上栗县| 托克托县| 本溪市| 台南市| 绍兴县|