Vue中的table表單切換實(shí)現(xiàn)效果
Vue表單切換實(shí)現(xiàn)效果
點(diǎn)擊第一個(gè)鏈接 出現(xiàn)以下數(shù)據(jù)

點(diǎn)擊第二個(gè)鏈接 ,我沒有寫后臺(tái)所以沒有數(shù)據(jù), 可以自己寫方法去獲取數(shù)據(jù)復(fù)制給v-model 綁定的數(shù)組

首先給兩個(gè)鏈接定義 一個(gè)num

點(diǎn)擊第一個(gè)按鈕時(shí) 設(shè)置num等于1 , 這樣在table列表處定義 v-show ="num==1 ",當(dāng)?shù)扔? 時(shí) 顯示第一個(gè)table 當(dāng)?shù)扔趎um 等于 2時(shí) 等于第二個(gè)table 這樣就能實(shí)現(xiàn) table 的轉(zhuǎn)換


table代碼在這里插入代碼片
<el-table v-show="num==1" :data="applicationList" border v-loading="dataListLoading" style="width: 100%"
@selection-change="selectionChangeHandle">
<el-table-column type="selection" align="center"></el-table-column>
<el-table-column
:index="indexMethod"
:resizable="false"
type="index" label="序號(hào)" align="center" width="60px"></el-table-column>
<el-table-column label="操作" align="center" width="150px">
<div slot-scope="scope" class="g-operation-column">
<el-link type="primary" size="mini" @click="show(scope.row)">編輯</el-link>
 
<el-link type="danger" size="mini" @click="del(scope.row)">刪除</el-link>
</div>
</el-table-column>
</el-table>
Data處定義 num

num 默認(rèn)值設(shè)定為1 這樣默認(rèn)就打開 第一個(gè)table 設(shè)置為0 就是都不打開
Vue table切換組件
如果vue單頁開發(fā)沒有使用ui組件,table切換的功能還是比較煩人的。閑暇時(shí)間看書寫了一個(gè)table切換的組件,和大家分享一下,效果圖如下:

主要有兩個(gè)組件頁面,第一個(gè)是 tabs.vue,這個(gè)頁面上會(huì)循環(huán)出table標(biāo)簽和每個(gè)標(biāo)簽對(duì)應(yīng)的內(nèi)容,大部分的事件處理也在這個(gè)頁面上。代碼如下:
<template>
<div class="tabs">
<div class="tabs-bar">
<div v-for="(item, index) in navList" @click="handleChange(index)" :class="tabCls(item)">
{{item.label}}
</div>
</div>
<div class="tabs-content">
<slot></slot>
</div>
</div>
</template>
<script>
export default {
name: "tabs",
props: {
value: {
type: [String, Number]
}
},
data(){
return{
currentValue: this.value,
navList: []
}
},
methods: {
tabCls: function (item) {
return [
'tabs-tab',
{
'tabs-tab-active': item.name === this.currentValue
}
]
},
getTabs: function () {
return this.$children.filter(function (item) {
return item.$options.name === 'pane';
})
},
updateNav: function () {
this.navList = [];
let _this = this;
this.getTabs().forEach(function (pane, index) {
_this.navList.push({
label: pane.label,
name: pane.name || index
});
if(!pane.name){
pane.name = index;
}
if(index === 0){
if(!_this.currentValue){
_this.currentValue = pane.name || index;
}
}
});
this.updateStatus();
},
updateStatus: function () {
let tabs = this.getTabs();
let _this = this;
tabs.forEach(function (tab) {
return tab.show = tab.name === _this.currentValue;
})
},
handleChange: function (index) {
let nav = this.navList[index];
let name = nav.name;
this.currentValue = name;
this.$emit('input', name);
this.$emit('on-click', name);
}
},
watch: {
value: function (val) {
this.currentValue = val;
},
currentValue: function () {
this.updateStatus();
}
}
}
</script>
<style scoped>
</style>第二個(gè)組件頁面是 pane.vue ,這個(gè)頁面主要是渲染和控制標(biāo)簽所對(duì)應(yīng)的內(nèi)容。代碼如下:
<template>
<div class="pane" v-show="show">
<slot></slot>
</div>
</template>
<script>
export default {
name: "pane",
props:{
name:{
type: String
},
label:{
type: String,
default: ''
}
},
data(){
return {
show: true
}
},
mounted(){
this.updateNav();
},
methods: {
updateNav: function () {
this.$parent.updateNav();
}
},
watch: {
label: function () {
this.updateNav();
}
}
}
</script>
<style scoped>
</style>使用這兩個(gè)頁面就很簡(jiǎn)單了,在頁面上引入這兩個(gè)組件,如下:
<template> ? ? <div> ? ? ? ? <tabs v-model="activeKey"> ? ? ? ? ? ? <pane label="標(biāo)簽一" name="1"> ? ? ? ? ? ? ? ? 標(biāo)簽一的內(nèi)容 ? ? ? ? ? ? </pane> ? ? ? ? ? ? <pane label="標(biāo)簽二" name="2"> ? ? ? ? ? ? ? ? 標(biāo)簽二的內(nèi)容 ? ? ? ? ? ? </pane> ? ? ? ? ? ? <pane label="標(biāo)簽三" name="3"> ? ? ? ? ? ? ? ? 標(biāo)簽三的內(nèi)容 ? ? ? ? ? ? </pane> ? ? ? ? </tabs> ? ? </div> </template>
<script>
? ? import Tabs from "../components/table/tabs";
? ? import Pane from "../components/table/pane";
? ? export default {
? ? ? ? name: "tableIndex",
? ? ? ? components: {Tabs,Pane},
? ? ? ? data(){
? ? ? ? ? ? return {
? ? ? ? ? ? ? ? activeKey: '1'
? ? ? ? ? ? }
? ? ? ? }
? ? }
</script>
<style>
? ? .tabs{
? ? ? ? font-size: 14px;
? ? ? ? color: #657180;
? ? }
? ? .tabs-bar:after{
? ? ? ? content:'';
? ? ? ? display: block;
? ? ? ? width: 100%;
? ? ? ? height:1px;
? ? ? ? background: #d7dde4;
? ? ? ? margin-top:-1px;
? ? }
? ? .tabs-tab{
? ? ? ? display: inline-block;
? ? ? ? padding: 4px 16px;
? ? ? ? margin-right: 6px;
? ? ? ? background: #fff;
? ? ? ? border: 1px solid #d7dde4;
? ? ? ? cursor: pointer;
? ? ? ? position: relative;
? ? }
? ? .tabs-tab-active{
? ? ? ? color: #3399ff;
? ? ? ? border-top: 1px solid #3399ff;
? ? ? ? border-bottom: 1px solid #fff;
? ? }
? ? .tabs-tab-active:before{
? ? ? ? content: '';
? ? ? ? display: block;
? ? ? ? height: 1px;
? ? ? ? background: #3399ff;
? ? ? ? position: absolute;
? ? ? ? top: 0;
? ? ? ? left: 0;
? ? ? ? right: 0;
? ? }
? ? .tabs-content{
? ? ? ? padding: 8px 0;
? ? }
</style>頁面上<tabs>標(biāo)簽定義了一個(gè)初始值“activeKey”,這是頁面初始時(shí)顯示的內(nèi)容,通常都是“1”,<pane>標(biāo)簽有個(gè)兩個(gè)屬性,一個(gè)是label,一個(gè)是name,主要是控制table標(biāo)簽主題的。每個(gè)table標(biāo)簽對(duì)應(yīng)的內(nèi)容直接寫在<pane></pane>標(biāo)簽里面就好了。組件雖然復(fù)雜了點(diǎn),但是復(fù)用起來還是可以的。
頁面的樣式我是寫在全局里面的(最后一個(gè)引入組件的頁面),沒有寫在組件頁面里面,使用的時(shí)候請(qǐng)多多注意
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- vue使用動(dòng)態(tài)組件實(shí)現(xiàn)TAB切換效果完整實(shí)例
- vue實(shí)現(xiàn)tab欄切換效果
- vue+iview?Table表格多選切換分頁保持勾選狀態(tài)
- vue?router如何實(shí)現(xiàn)tab切換
- vue實(shí)現(xiàn)鼠標(biāo)滑動(dòng)展示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)文章
手把手教你如何創(chuàng)建一個(gè)VUE項(xiàng)目(超簡(jiǎn)單)
這篇文章主要給大家介紹了關(guān)于如何創(chuàng)建一個(gè)VUE項(xiàng)目的相關(guān)資料,創(chuàng)建vue項(xiàng)目有很多種方式,這里給大家介紹一種非常簡(jiǎn)單的方法,需要的朋友可以參考下2023-08-08
快速解決vue2+vue-cli3項(xiàng)目ie兼容的問題
這篇文章主要介紹了快速解決vue2+vue-cli3項(xiàng)目ie兼容的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-11-11
Vue+abp微信掃碼登錄的實(shí)現(xiàn)代碼示例
這篇文章主要介紹了Vue+abp微信掃碼登錄的實(shí)現(xiàn)代碼示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01
vue實(shí)現(xiàn)多個(gè)tab標(biāo)簽頁的切換與關(guān)閉詳細(xì)代碼
這篇文章主要給大家介紹了關(guān)于vue實(shí)現(xiàn)多個(gè)tab標(biāo)簽頁的切換與關(guān)閉的相關(guān)資料,使用vue.js實(shí)現(xiàn)tab切換很簡(jiǎn)單,文中通過代碼示例介紹的非常詳細(xì),需要的朋友可以參考下2023-10-10
ant-design-vue Table pagination分頁實(shí)現(xiàn)全過程
這篇文章主要介紹了ant-design-vue Table pagination分頁實(shí)現(xiàn)全過程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04

