Vue2.0 多 Tab切換組件的封裝實(shí)例
Vue2.0 多 Tab切換組件簡(jiǎn)單封裝,滿足自己簡(jiǎn)單的功能,可以直接拿去使用!
首先上效果圖:

功能簡(jiǎn)單介紹:
1、支持tab切換
2、支持tab定位
3、支持tab自動(dòng)化
仿React多Tab實(shí)現(xiàn),總之可以正常使用滿足日常需求,
1、使用方法:
==index.vue文件==
<TabItems>
<div name="買入" class="first">
<Content :isContTab = "0" />
</div>
<div name="自動(dòng)再平衡" class="second">
<Content :isContTab = "1" />
</div>
<div name="一鍵賣出" class="three">
<Content :isContTab = "2" />
</div>
</TabItems>
PS:TabItems是我的TabSwitch組件,tab頁(yè)面標(biāo)題就是 div 中的name值,倆面是內(nèi)容,也可以是子組件。
接下來(lái)展示TabItems組件
2、組件
index.less文件
body,html {margin: 0;}
* {
opacity: 1;
-webkit-backface-visibility: hidden;
}
.tabItems {
.Tab_tittle_wrap {
position: absolute;
width: 100%;
top: 0;
z-index: 2;
background: @ffffff;
display: -webkit-box;
height: 80px;
line-height: 80px;
text-align: center;
color: @222222;
border-bottom: 1px solid rgba(46, 177, 255, 0.08);
box-shadow: 0px 0px 25px 6px rgba(46, 177, 255, 0.21);
span {
display: block;
text-align: center;
width: 26%;
margin: 0 24px;
font-size: 26px;
position: relative;
i {
display: inline-block;
position: absolute;
width: 1px;
height: 50px;
top: 15px;
right: -24px;
background: @dddddd;
}
&:last-child {
i {
display: none;
}
}
}
.router-link-active {
color: #8097f9;
border-bottom: 1px solid #8097f9;
}
}
.Tab_item_wrap {
position: absolute;
top: 82px;
width: 100%;
z-index: 0;
background: @ffffff;
bottom: 0;
overflow-x: hidden;
-webkit-overflow-scrolling: touch;
}
.showAnminous {
opacity: 1;
-webkit-backface-visibility: hidden;
-webkit-animation-name: "rightMove";
/*動(dòng)畫名稱,需要跟@keyframes定義的名稱一致*/
-webkit-animation-duration: .3s;
/*動(dòng)畫持續(xù)的時(shí)間長(zhǎng)*/
-webkit-animation-iteration-count: 1;
/*動(dòng)畫循環(huán)播放的次數(shù)為1 infinite為無(wú)限次*/
}
}
@-webkit-keyframes rightMove {
0% {
-webkit-transform: translate(110%, 0);
}
100% {
-webkit-transform: translate(0, 0);
}
}
@-ms-keyframes rightMove {
0% {
-ms-transform: translate(110%, 0);
}
100% {
-ms-transform: translate(0, 0);
}
}
@keyframes rightMove {
0% {
-webkit-transform: translate(110%, 0);
-ms-transform: translate(110%, 0);
transform: translate(110%, 0);
}
100% {
-webkit-transform: translate(0, 0);
-ms-transform: translate(0, 0);
transform: translate(0, 0);
}
}
TabItems.vue
<template>
<div class="tabItems">
<div class="Tab_tittle_wrap" @click="tabswitch">
<span v-for="(v,i) in tabTitle" :style="{width:(100/tabTitle.length-7.5)+'%'}" :class="isShowTab==i?'router-link-active':''">{{v}}<i></i></span>
</div>
<div class="Tab_item_wrap">
<slot></slot>
</div>
</div>
</template>
<style lang="less">
@import "./less/index";
</style>
<script>
export default {
data() {
return {
tabTitle: [],
isShowTab: 0,
}
},
created: function() {
let is = sessionStorage.getItem("isTabShow");
if(is) {
this.isShowTab = is;
} else {
let URL = libUtils.GetURLParamObj();
this.isShowTab = URL.isShowTab ? URL.isShowTab : "0";
}
setTimeout(function() {
this.tabswitch(document.querySelector(".Tab_tittle_wrap").children[this.isShowTab].click());
}.bind(this), 0);
},
mounted() {
let slot = this.$slots.default;
for(let i = 0; i < slot.length; i++) {
if(slot[i].tag == "div") {
this.tabTitle.push(slot[i].data.attrs.name);
if(slot[i].elm) {
slot[i].elm.className = "hide";
if(this.isShowTab == i) {
slot[i].elm.className = "";
}
};
}
}
},
methods: {
tabswitch() {
if(!event) return;
let target = event.target;
if(target.nodeName.toLowerCase() !== 'span') {
return;
}
let len = target.parentNode.children;
for(let i = 0; i < len.length; i++) {
len[i].index = i;
len[i].removeAttribute('class');
}
target.setAttribute('class', 'router-link-active');
this.isShowTab = target.index;
//tabItems
let child = this.$el.children[1].children;
for(let k = 0; k < child.length; k++) {
child[k].className = "hide";
if(k == target.index) {
child[k].className = "showAnminous";
}
}
try {
sessionStorage.setItem("isTabShow", target.index);
} catch(err) {
console.log(err);
}
}
}
}
</script>
PS:
created、mounted這兩個(gè)方法不需要過(guò)多介紹,Vue生命周期
1、created方法介紹。
獲取瀏覽器鏈接地址:libUtils.GetURLParamObj();獲取瀏覽器鏈接地址的
created這個(gè)方法主要是用來(lái)定位tab具體顯示哪個(gè)頁(yè)面的
2、mounted方法介紹
主要是用于隱藏內(nèi)容容器的
3、tabswitch方法
用來(lái)切換組件容器的顯示的頁(yè)面!
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue實(shí)現(xiàn)tab路由切換組件的方法實(shí)例
- vue使用動(dòng)態(tài)組件實(shí)現(xiàn)TAB切換效果
- Vue切換Tab動(dòng)態(tài)渲染組件的操作
- vue組件開發(fā)之tab切換組件使用詳解
- Vue可自定義tab組件用法實(shí)例
- Vue render函數(shù)實(shí)戰(zhàn)之實(shí)現(xiàn)tabs選項(xiàng)卡組件
- 詳解vue2.0 使用動(dòng)態(tài)組件實(shí)現(xiàn) Tab 標(biāo)簽頁(yè)切換效果(vue-cli)
- vue.js移動(dòng)端tab組件的封裝實(shí)踐實(shí)例
- Vue.js組件tab實(shí)現(xiàn)選項(xiàng)卡切換
- Vue.js組件tabs實(shí)現(xiàn)選項(xiàng)卡切換效果
- vue封裝tabs組件案例詳解
相關(guān)文章
ElementPlus el-message-box樣式錯(cuò)位問(wèn)題及解決
這篇文章主要介紹了ElementPlus el-message-box樣式錯(cuò)位問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
vue使用vuedraggable實(shí)現(xiàn)嵌套多層拖拽排序功能
這篇文章主要為大家詳細(xì)介紹了vue使用vuedraggable實(shí)現(xiàn)嵌套多層拖拽排序功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
vue中keep-alive組件實(shí)現(xiàn)多級(jí)嵌套路由的緩存
本文主要介紹了vue中keep-alive組件實(shí)現(xiàn)多級(jí)嵌套路由的緩存,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
基礎(chǔ)的前端vite項(xiàng)目創(chuàng)建過(guò)程詳解
這篇文章主要介紹了如何使用Vite創(chuàng)建一個(gè)前端項(xiàng)目,并配置了Vue?Router、Vuex、Element?Plus、Axios和Element?Plus圖標(biāo)等第三方依賴,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-11-11
mpvue項(xiàng)目中使用第三方UI組件庫(kù)的方法
這篇文章主要介紹了mpvue項(xiàng)目中使用第三方UI組件庫(kù)的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-09-09
關(guān)于element-ui表頭吸附問(wèn)題的解決方案
數(shù)據(jù)過(guò)多滑動(dòng)表格的時(shí)候,看不到表頭不知道對(duì)應(yīng)的數(shù)據(jù)是什么,用戶體驗(yàn)操作不友好,要改成表頭固定住,所以本文給大家介紹了關(guān)于element-ui表頭吸附問(wèn)題的兩個(gè)解決方案,需要的朋友可以參考下2024-01-01

