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

vue實現(xiàn)動態(tài)控制表格列的顯示隱藏

 更新時間:2022年04月12日 11:37:56   作者:熱忱!  
這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)動態(tài)控制表格列的顯示隱藏,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了vue實現(xiàn)動態(tài)控制表格列顯示隱藏的具體代碼,供大家參考,具體內(nèi)容如下

一、效果

如上圖所示,點擊table右上方的表格按鈕,彈出菜單欄,進(jìn)行勾選,從而達(dá)到表格對應(yīng)列顯示和隱藏

二、代碼

1.HTML部分

<template>
? <div id="app">
? ? <el-table :data="tableData" border style="width: 100%" ref="table">
? ? ? <el-table-column
? ? ? ? fixed
? ? ? ? prop="date"
? ? ? ? label="日期"
? ? ? ? width="150"
? ? ? ? v-if="showColumn.date"
? ? ? >
? ? ? </el-table-column>
? ? ? <el-table-column
? ? ? ? prop="name"
? ? ? ? label="姓名"
? ? ? ? width="120"
? ? ? ? v-if="showColumn.name"
? ? ? >
? ? ? </el-table-column>
? ? ? <el-table-column
? ? ? ? prop="province"
? ? ? ? label="省份"
? ? ? ? width="120"
? ? ? ? v-if="showColumn.provinces"
? ? ? >
? ? ? </el-table-column>
? ? ? <el-table-column
? ? ? ? prop="city"
? ? ? ? label="市區(qū)"
? ? ? ? width="120"
? ? ? ? v-if="showColumn.city"
? ? ? >
? ? ? </el-table-column>
? ? ? <el-table-column
? ? ? ? prop="address"
? ? ? ? label="地址"
? ? ? ? width="300"
? ? ? ? v-if="showColumn.adreess"
? ? ? >
? ? ? </el-table-column>
? ? ? <el-table-column
? ? ? ? prop="zip"
? ? ? ? label="郵編"
? ? ? ? width="120"
? ? ? ? v-if="showColumn.zipCode"
? ? ? >
? ? ? </el-table-column>
? ? ? <el-table-column fixed="right" width="100" align="center">
? ? ? ? <template slot="header">
? ? ? ? ? <i
? ? ? ? ? ? class="el-icon-setting"
? ? ? ? ? ? style="font-size: 22px; cursor: pointer"
? ? ? ? ? ? @click="showColumnOption"
? ? ? ? ? ></i>
? ? ? ? </template>
? ? ? ? <template slot-scope="scope">
? ? ? ? ? <el-button @click="handleClick(scope.row)" type="text" size="small"
? ? ? ? ? ? >查看</el-button
? ? ? ? ? >
? ? ? ? ? <el-button type="text" size="small">編輯</el-button>
? ? ? ? </template>
? ? ? </el-table-column>
? ? </el-table>
? ? <!-- 配置列面板 -->
? ? <transition name="fade">
? ? ? <div class="columnOption" v-show="isShowColumn">
? ? ? ? <div class="content">
? ? ? ? ? <div class="head">選擇顯示字段</div>
? ? ? ? ? <div class="body">
? ? ? ? ? ? <el-checkbox v-model="checkList.date" disabled>日期</el-checkbox>
? ? ? ? ? ? <el-checkbox v-model="checkList.name">姓名</el-checkbox>
? ? ? ? ? ? <el-checkbox v-model="checkList.provinces">省份</el-checkbox>
? ? ? ? ? ? <el-checkbox v-model="checkList.city">市區(qū)</el-checkbox>
? ? ? ? ? ? <el-checkbox v-model="checkList.adreess">地址</el-checkbox>
? ? ? ? ? ? <el-checkbox v-model="checkList.zipCode">郵編</el-checkbox>
? ? ? ? ? </div>
? ? ? ? ? <div class="footer">
? ? ? ? ? ? <el-button size="small" type="primary" plain @click="saveColumn"
? ? ? ? ? ? ? >保存列配置</el-button
? ? ? ? ? ? >
? ? ? ? ? </div>
? ? ? ? </div>
? ? ? </div>
? ? </transition>
? </div>
</template>

通過 v-if="showColumn.date" 來判斷表格對應(yīng)列的狀態(tài)

2.javascript部分

<script>
export default {
? data() {
? ? return {
? ? ? isShowColumn: false,
? ? ? tableData: [
? ? ? ? {
? ? ? ? ? date: "2016-05-02",
? ? ? ? ? name: "王小虎",
? ? ? ? ? province: "上海",
? ? ? ? ? city: "普陀區(qū)",
? ? ? ? ? address: "上海市普陀區(qū)金沙江路 1518 弄",
? ? ? ? ? zip: 200333,
? ? ? ? },
? ? ? ? {
? ? ? ? ? date: "2016-05-04",
? ? ? ? ? name: "王小虎",
? ? ? ? ? province: "上海",
? ? ? ? ? city: "普陀區(qū)",
? ? ? ? ? address: "上海市普陀區(qū)金沙江路 1517 弄",
? ? ? ? ? zip: 200333,
? ? ? ? },
? ? ? ? {
? ? ? ? ? date: "2016-05-01",
? ? ? ? ? name: "王小虎",
? ? ? ? ? province: "上海",
? ? ? ? ? city: "普陀區(qū)",
? ? ? ? ? address: "上海市普陀區(qū)金沙江路 1519 弄",
? ? ? ? ? zip: 200333,
? ? ? ? },
? ? ? ? {
? ? ? ? ? date: "2016-05-03",
? ? ? ? ? name: "王小虎",
? ? ? ? ? province: "上海",
? ? ? ? ? city: "普陀區(qū)",
? ? ? ? ? address: "上海市普陀區(qū)金沙江路 1516 弄",
? ? ? ? ? zip: 200333,
? ? ? ? },
? ? ? ],
? ? ? // 列的配置化對象,存儲配置信息
? ? ? checkList: {},
? ? ? showColumn: {
? ? ? ? date: true,
? ? ? ? name: true,
? ? ? ? provinces: true,
? ? ? ? city: true,
? ? ? ? adreess: true,
? ? ? ? zipCode: true,
? ? ? },
? ? };
? },
? watch: {
? ? // 監(jiān)聽復(fù)選框配置列所有的變化
? ? checkList: {
? ? ? handler: function (newnew, oldold) {
? ? ? ? // console.log(newnew);?
? ? ? ? this.showColumn = newnew;
? ? ? ? // 這里需要讓表格重新繪制一下,否則會產(chǎn)生固定列錯位的情況
? ? ? ? this.$nextTick(() => {
? ? ? ? ? this.$refs.table.doLayout();
? ? ? ? });
? ? ? },
? ? ? deep: true,
? ? ? immediate: true
? ? },
? },
? mounted() {
? ? // 發(fā)請求得到checkListInitData的列的名字
? ? if(localStorage.getItem("columnSet")){
? ? ? this.checkList = JSON.parse(localStorage.getItem("columnSet"))
? ? }else{
? ? ? this.checkList = {
? ? ? ? date: true,
? ? ? ? name: true,
? ? ? ? provinces: true,
? ? ? ? city: true,
? ? ? ? adreess: true,
? ? ? ? zipCode: true,
? ? ? };
? ? }
? },
? methods: {
? ? handleClick(row) {
? ? ? console.log(row);
? ? },
? ? showColumnOption() {
? ? ? this.isShowColumn = true;
? ? },
? ? saveColumn() {
? ? ? localStorage.setItem("columnSet",JSON.stringify(this.checkList))
? ? ? this.isShowColumn = false;
? ? },
? },
};
</script>

3.css樣式部分

?.columnOption {
? position: fixed;
? z-index: 20;
? top: 0;
? left: 0;
? width: 100%;
? height: 100%;
? background-color: rgba(0, 0, 0, 0.3);
? display: flex;
? flex-direction: row-reverse;
? .content {
? ? width: 100px;
? ? height: 100%;
? ? background-color: rgb(203, 223, 198);
? ? .head {
? ? ? width: 100%;
? ? ? height: 44px;
? ? ? border-bottom: 1px solid #000;
? ? ? display: flex;
? ? ? justify-content: center;
? ? ? align-items: center;
? ? ? font-size: 12px;
? ? }
? ? .body {
? ? ? width: 100%;
? ? ? height: calc(100% - 88px);
? ? ? box-sizing: border-box;
? ? ? padding-top: 10px;
? ? ? overflow-y: auto;
? ? ? .items {
? ? ? ? width: 100%;
? ? ? ? height: 100%;
? ? ? ? overflow-y: auto;
? ? ? ? display: flex;
? ? ? ? flex-direction: column;
? ? ? ? .el-checkbox {
? ? ? ? ? width: 100%;
? ? ? ? ? height: 28px;
? ? ? ? ? line-height: 28px;
? ? ? ? ? margin-bottom: 14px;
? ? ? ? ? display: inline-block;
? ? ? ? ? font-family: PingFang SC;
? ? ? ? ? font-style: normal;
? ? ? ? ? font-weight: normal;
? ? ? ? ? font-size: 14px;
? ? ? ? ? color: #000;
? ? ? ? ? overflow: hidden;
? ? ? ? ? text-overflow: ellipsis;
? ? ? ? ? white-space: nowrap;
? ? ? ? ? box-sizing: border-box;
? ? ? ? ? padding-left: 14px;
? ? ? ? }
? ? ? ? .el-checkbox:hover {
? ? ? ? ? background-color: #f5f7fa;
? ? ? ? }
? ? ? }
? ? }
? ? .footer {
? ? ? width: 100%;
? ? ? height: 44px;
? ? ? border-top: 1px solid #000;
? ? ? display: flex;
? ? ? justify-content: center;
? ? ? align-items: center;
? ? }
? }
}
// 控制淡入淡出效果
.fade-enter-active,
.fade-leave-active {
? transition: opacity 0.3s;
}
.fade-enter,
.fade-leave-to {
? opacity: 0;
}

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

相關(guān)文章

  • elementui中tabel組件的scope.$index的使用及說明

    elementui中tabel組件的scope.$index的使用及說明

    這篇文章主要介紹了elementui中tabel組件的scope.$index的使用及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-10-10
  • 從0搭建Vue3組件庫之如何使用Vite打包組件庫

    從0搭建Vue3組件庫之如何使用Vite打包組件庫

    這篇文章主要介紹了從0搭建Vue3組件庫之如何使用Vite打包組件庫,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-03-03
  • Vue中使用富文本編輯框的實踐與探索

    Vue中使用富文本編輯框的實踐與探索

    本文詳細(xì)介紹了如何在Vue項目中集成和使用富文本編輯框,并分享了一些實踐經(jīng)驗,介紹了為什么需要富文本編輯框,Vue中常用的富文本編輯器,以及如何安裝、配置和使用Vue-Quill-Editor,本文還提供了一些基本的配置示例,幫助開發(fā)者在實際項目中根據(jù)需求進(jìn)行更多探索和定制
    2024-10-10
  • vue等兩個接口都返回結(jié)果再執(zhí)行下一步的實例

    vue等兩個接口都返回結(jié)果再執(zhí)行下一步的實例

    這篇文章主要介紹了vue等兩個接口都返回結(jié)果再執(zhí)行下一步的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • Vue路由跳轉(zhuǎn)步驟詳解

    Vue路由跳轉(zhuǎn)步驟詳解

    這篇文章主要介紹了?Vue路由跳轉(zhuǎn)步驟詳解,主要介紹當(dāng)訪問API成功后跳轉(zhuǎn)到新的Vue頁面怎么處理,感興趣的朋友跟隨小編一起看看吧
    2023-07-07
  • vue+element-ui前端使用print-js實現(xiàn)打印功能(可自定義樣式)

    vue+element-ui前端使用print-js實現(xiàn)打印功能(可自定義樣式)

    Print.js主要是為了幫助我們直接在瀏覽器中開發(fā)打印功能,下面這篇文章主要給大家介紹了關(guān)于vue+element-ui前端使用print-js實現(xiàn)打印功能(可自定義樣式)的相關(guān)資料,需要的朋友可以參考下
    2022-11-11
  • ???????基于el-table和el-pagination實現(xiàn)數(shù)據(jù)的分頁效果

    ???????基于el-table和el-pagination實現(xiàn)數(shù)據(jù)的分頁效果

    本文主要介紹了???????基于el-table和el-pagination實現(xiàn)數(shù)據(jù)的分頁效果,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • 在Vue中使用axios請求攔截的實現(xiàn)方法

    在Vue中使用axios請求攔截的實現(xiàn)方法

    這篇文章主要介紹了在Vue中使用axios請求攔截,需要的朋友可以參考下
    2018-10-10
  • 解決vue-router路由攔截造成死循環(huán)問題

    解決vue-router路由攔截造成死循環(huán)問題

    這篇文章主要介紹了解決vue-router路由攔截造成死循環(huán)問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-08-08
  • vue keep-alive中的生命周期解讀

    vue keep-alive中的生命周期解讀

    這篇文章主要介紹了vue keep-alive中的生命周期,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10

最新評論

姚安县| 南岸区| 隆尧县| 漠河县| 遵化市| 汉源县| 孟津县| 怀远县| 武穴市| 大丰市| 沽源县| 甘孜县| 尤溪县| 含山县| 井研县| 东阿县| 江口县| 元氏县| 辽宁省| 乌什县| 阳城县| 芜湖市| 长治县| 集安市| 嘉峪关市| 丰镇市| 蒲城县| 常山县| 射洪县| 萝北县| 抚宁县| 崇仁县| 汾西县| 日照市| 清徐县| 惠来县| 金乡县| 昭觉县| 肇州县| 洛南县| 大港区|