vue實(shí)現(xiàn)tab欄切換效果
本文實(shí)例為大家分享了vue實(shí)現(xiàn)tab欄切換效果的具體代碼,供大家參考,具體內(nèi)容如下
一個簡單的tab欄切換組件,由tabs以及tab-pane組成
效果圖

使用
<template> ? <div class="container"> ? ? <tabs ? ? ? default-active="2" ? ? ? class="build-tabs" ? ? > ? ? ? <tab-pane ? ? ? ? label="tab欄標(biāo)題1" ? ? ? ? index="1" ? ? ? >tab欄內(nèi)容1</tab-pane> ? ? ? <tab-pane ? ? ? ? label="tab欄標(biāo)題tab欄標(biāo)題2" ? ? ? ? index="2" ? ? ? > ? ? ? ? tab欄內(nèi)容2 ? ? ? </tab-pane> ? ? ? <tab-pane ? ? ? ? label="tab欄標(biāo)題" ? ? ? ? index="3" ? ? ? >tab欄內(nèi)容3</tab-pane> ? ? ? <tab-pane ? ? ? ? label="標(biāo)題" ? ? ? ? index="4" ? ? ? >tab欄內(nèi)容4</tab-pane> ? ? ? <tab-pane ? ? ? ? label="tab欄標(biāo)題3" ? ? ? ? index="5" ? ? ? >tab欄內(nèi)容5</tab-pane> ? ? </tabs> ? </div> </template>
tabs
<template>
? <div
? ? v-show="pans.length"
? ? class="tabs"
? >
? ? <div class="tab-title">
? ? ? <div
? ? ? ? v-for="(item) in pans"
? ? ? ? :key="item.id"
? ? ? ? class="item"
? ? ? ? :class="{ 'active': currentActive === item.index }"
? ? ? ? @click="changeTab(item.index)"
? ? ? >{{ item.label }}</div>
? ? </div>
? ? <div class="tab-content">
? ? ? <slot></slot>
? ? </div>
? </div>
</template>
<script>
export default {
? props: {
? ? mode: {
? ? ? type: String,
? ? ? default: "horizontal/vertical"
? ? },
? ? defaultActive: {
? ? ? type: String | Number,
? ? ? default: '1'
? ? },
? ? defaultColor: {
? ? ? type: String,
? ? ? default: '#409EFF'
? ? }
? },
? data: () => {
? ? return {
? ? ? currentActive: '',
? ? ? pans: []
? ? }
? },
? computed: {
? },
? watch: {
? ? defaultActive: {
? ? ? handler (newVal) {
? ? ? ? this.currentActive = newVal
? ? ? },
? ? ? immediate: true
? ? }
? },
? mounted () {
? },
? methods: {
? ? changeTab (val) {
? ? ? this.currentActive = val
? ? },
? }
}
</script>
<style scoped lang="scss">
::root {
? --color: "#409EFF";
}
.tabs {
? .tab-title {
? ? display: flex;
? ? // align-items: flex-start;
? ? align-items: stretch;?? ?// 側(cè)邊欄時,使側(cè)欄高度與內(nèi)容高度一致,按最高的顯示
? ? margin-bottom: 14px;
? ? border-bottom: 1px solid #ccc;
? ? .item {
? ? ? padding: 20px;
? ? ? /* padding-bottom: 20px; */
? ? ? cursor: pointer;
? ? ? white-space: nowrap;
? ? }
? ? .active {
? ? ? // color: var(--color);
? ? ? color: #409EFF;
? ? ? /* padding-bottom: 15px; // 修正邊框值:20px - 5px = 15px */
? ? ? border-bottom: 5px solid #409EFF;
? ? ? background-image: linear-gradient(
? ? ? ? to top,
? ? ? ? rgba($color: #409EFF, $alpha: 0.2),
? ? ? ? transparent
? ? ? );
? ? }
? }
}
</style>tab-pane
<template>
? <div
? ? v-show="show && renderPan"
? ? class="tab-pane"
? >
? ? <slot></slot>
? </div>
</template>
<script>
export default {
? name: 'tabPane',
? props: {
? ? index: {
? ? ? type: [String, Number],
? ? ? default: ''
? ? },
? ? label: {
? ? ? type: String,
? ? ? required: true
? ? }
? },
? data: () => {
? ? return {
? ? ? renderPan: false
? ? }
? },
? computed: {
? ? show () {
? ? ? if (this.$parent.currentActive === this.index) return true
? ? ? return false
? ? }
? },
? mounted () {
? ? this.$parent.pans.push({ id: Date.parse(new Date()) + Math.random(), index: this.index, label: this.label });
? ? this.renderPan = true
? },
? methods: {
? },
}
</script>
<style scoped lang="scss">
</style>以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue使用動態(tài)組件實(shí)現(xiàn)TAB切換效果完整實(shí)例
- Vue中的table表單切換實(shí)現(xiàn)效果
- vue+iview?Table表格多選切換分頁保持勾選狀態(tài)
- vue?router如何實(shí)現(xiàn)tab切換
- vue實(shí)現(xiàn)鼠標(biāo)滑動展示tab欄切換
- Vue實(shí)現(xiàn)選項(xiàng)卡tab切換制作
- vue實(shí)現(xiàn)tab切換的3種方式及切換保持?jǐn)?shù)據(jù)狀態(tài)
- vue實(shí)現(xiàn)tab路由切換組件的方法實(shí)例
- Vue實(shí)現(xiàn)tab切換的兩種方法示例詳解
相關(guān)文章
vue keep-alive實(shí)現(xiàn)多組件嵌套中個別組件存活不銷毀的操作
這篇文章主要介紹了vue keep-alive實(shí)現(xiàn)多組件嵌套中個別組件存活不銷毀的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-10-10
vue2項(xiàng)目使用element-ui的el-tabs組件導(dǎo)致瀏覽器崩潰卡死問題
這篇文章主要介紹了vue2項(xiàng)目使用element-ui的el-tabs組件導(dǎo)致瀏覽器崩潰卡死問題及解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07
vue 中 elment-ui table合并上下兩行相同數(shù)據(jù)單元格
這篇文章主要介紹了vue 中 elment-ui table合并上下兩行相同數(shù)據(jù)單元格,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-12-12
vue parseHTML函數(shù)源碼解析 AST預(yù)備知識
這篇文章主要為大家介紹了vue parseHTML函數(shù)源碼解析 AST預(yù)備知識示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
Element DateTimePicker日期時間選擇器的使用示例
這篇文章主要介紹了Element DateTimePicker日期時間選擇器的使用示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07
詳解vue2.0 使用動態(tài)組件實(shí)現(xiàn) Tab 標(biāo)簽頁切換效果(vue-cli)
本篇文章主要介紹了詳解vue2.0 使用動態(tài)組件實(shí)現(xiàn) Tab 標(biāo)簽頁切換效果(vue-cli),具有一定的參考價值,有需要的可以了解下2017-08-08

