欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

elementUI Table組件實(shí)現(xiàn)表頭吸頂效果(示例代碼)

 更新時(shí)間:2025年01月23日 11:17:16   作者:熱忱1128  
文章介紹了如何在vue2.6+和elementUI環(huán)境下實(shí)現(xiàn)el-table組件的表頭吸頂效果,通過添加樣式、注冊(cè)指令、引入指令并在父元素中避免使用overflow:hidden,可以實(shí)現(xiàn)場景下表頭始終可見,本文通過實(shí)例代碼介紹的非常詳細(xì),感興趣的朋友一起看看吧

需求描述

當(dāng) table 內(nèi)容過多的時(shí)候,頁面上滑滾動(dòng),表頭的信息也會(huì)隨著被遮擋,無法將表頭信息和表格內(nèi)容對(duì)應(yīng)起來,需要進(jìn)行表頭吸頂

開始編碼??

環(huán)境:vue2.6+、element UI
step1:el-table__header-wrapper加上樣式

//style/sticky-table-header.scss
.el-table[is-sticky] {
  overflow: initial;
  --sticky-top: 0px;
  --stick-zIndex: 5;
  .el-table__header-wrapper{
    position: sticky;
    top: var(--sticky-top);
    z-index: var(--stick-zIndex);
  }
  .el-table__fixed, .el-table__fixed-right{
    overflow: visible;
    z-index: var(--stick-zIndex);
    .el-table__fixed-header-wrapper {
      position: sticky;
      top: var(--sticky-top);
      width: 100%;
      overflow: hidden;
      z-index: var(--stick-zIndex);
    }
    .el-table__fixed-body-wrapper {
      width: 100%;
      overflow: hidden;
    }
  }
  .el-table__fixed-right {
    .el-table__fixed-header-wrapper {
      display: flex;
      justify-content: flex-end;
    }
    .el-table__fixed-body-wrapper {
      display: flex;
      justify-content: flex-end;
    }
  }
  &.el-table--border::after{
    z-index: var(--stick-zIndex);
  }
}
.el-table__fixed {
  --box-shadow: 10px 0 10px -10px rgba(0, 0, 0, 0.12);
}
.el-table__fixed-right {
  --box-shadow: -10px 0 10px -10px rgba(0, 0, 0, 0.12);
}
.el-table__fixed, .el-table__fixed-right {
  box-shadow: var(--box-shadow);
}

step2: 注冊(cè)指令 directives/sticky-header.js

import '@/styles/sticky-table-header.scss'
export default {
  bind(el, binding) {
    el.setAttribute('is-sticky', true)
    updateStickyTop(el, binding)
  },
  update(el, binding) {
    updateStickyTop(el, binding)
  }
}
const updateStickyTop = (el, binding) => {
  const { value, oldValue } = binding
  if (value === oldValue) return
  const top = Number(value)
  if (!isNaN(top)) {
    el.style.setProperty('--sticky-top', `${top}px`)
  }
}

step3: main.js 引入

import StickyTableHeader from './directives/sticky-header'
Vue.directive('sticky-table-header', StickyTableHeader)

step4: table.vue

<template>
  <div class="wrapper">
    <h3>純CSS表格吸頂</h3>
    <el-radio-group v-model="mode" aria-hidden="true" class="options">
      <el-radio label="normal">正常模式</el-radio>
      <el-radio label="fixedLeft">固定左邊列</el-radio>
      <el-radio label="fixedRight">固定右邊列</el-radio>
      <el-radio label="fixedLeftRight">固定左右列</el-radio>
    </el-radio-group>
    <el-table
      v-sticky-table-header="0"
      border
      :data="tableData"
    >
      <el-table-column label="日期" prop="date" min-width="150" :fixed="fixedLeft" />
      <el-table-column label="姓名" prop="name" width="120" />
      <el-table-column label="省份" prop="province" width="120" />
      <el-table-column label="市區(qū)" prop="city" width="120" />
      <el-table-column label="地址" prop="address" width="300" />
      <el-table-column label="郵編" prop="zip" min-width="120" :fixed="fixedRight" />
    </el-table>
  </div>
</template>
<script>
export default {
  name: 'CSSFixedTopTable',
  components: {},
  data() {
    const tableData = new Array(100).fill(0).map((_, index) => {
      return {
        date: '2016-05-03',
        name: '王小虎',
        province: '上海',
        city: '普陀區(qū)',
        address: `上海市普陀區(qū)金沙江路 ${1 + index} 弄`,
        zip: 2000001 + index
      }
    })
    return {
      tableData,
      mode: 'normal'
    }
  },
  computed: {
    fixedLeft() {
      return /left/i.test(this.mode) ? 'left' : null
    },
    fixedRight() {
      return /right/i.test(this.mode) ? 'right' : null
    }
  },
  methods: {}
}
</script>
<style lang="scss" scoped>
.wrapper {
  width: 800px;
  margin: 0 auto;
  .options {
    width: 100%;
    margin: 30px 0;
    text-align: left;
  }
}
</style>

??????父元素不要有 overflow: hidden;會(huì)失效

step5: 效果呈現(xiàn)??

到此這篇關(guān)于elementUI Table組件實(shí)現(xiàn)表頭吸頂效果的文章就介紹到這了,更多相關(guān)elementUI Table組件表頭吸頂內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue中數(shù)據(jù)綁定值(字符串拼接)的幾種實(shí)現(xiàn)方法

    vue中數(shù)據(jù)綁定值(字符串拼接)的幾種實(shí)現(xiàn)方法

    這篇文章主要介紹了vue中數(shù)據(jù)綁定值(字符串拼接)的幾種實(shí)現(xiàn)方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-07-07
  • Vue組件通信$attrs、$listeners實(shí)現(xiàn)原理解析

    Vue組件通信$attrs、$listeners實(shí)現(xiàn)原理解析

    這篇文章主要介紹了Vue組件通信$attrs、$listeners實(shí)現(xiàn)原理解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • 使用vite兼容低端瀏覽器配置

    使用vite兼容低端瀏覽器配置

    這篇文章主要介紹了使用vite兼容低端瀏覽器配置方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-05-05
  • vue實(shí)現(xiàn)簡易圖片左右旋轉(zhuǎn),上一張,下一張組件案例

    vue實(shí)現(xiàn)簡易圖片左右旋轉(zhuǎn),上一張,下一張組件案例

    這篇文章主要介紹了vue實(shí)現(xiàn)簡易圖片左右旋轉(zhuǎn),上一張,下一張組件案例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • Vue 富文本編輯器tinymce的安裝配置使用教程

    Vue 富文本編輯器tinymce的安裝配置使用教程

    TinyMCE是一個(gè)輕量級(jí)的基于瀏覽器的所見即所得編輯器,由JavaScript寫成,TinyMCE是一個(gè)根據(jù)LGPL license發(fā)布的自由軟件,你可以把它用于商業(yè)應(yīng)用,這篇文章主要介紹了Vue 富文本編輯器tinymce的安裝教程,需要的朋友可以參考下
    2023-09-09
  • vue中給路徑起別名的實(shí)現(xiàn)方法

    vue中給路徑起別名的實(shí)現(xiàn)方法

    本文主要介紹了vue中給路徑起別名的實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • Vue?設(shè)置圖片不轉(zhuǎn)為base64的方式

    Vue?設(shè)置圖片不轉(zhuǎn)為base64的方式

    這篇文章主要介紹了Vue實(shí)現(xiàn)設(shè)置圖片不轉(zhuǎn)為base64的方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • vue 如何實(shí)現(xiàn)配置@絕對(duì)路徑

    vue 如何實(shí)現(xiàn)配置@絕對(duì)路徑

    這篇文章主要介紹了vue 如何實(shí)現(xiàn)配置@絕對(duì)路徑,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • vue3動(dòng)態(tài)添加路由

    vue3動(dòng)態(tài)添加路由

    這篇文章主要介紹了vue3動(dòng)態(tài)添加路由,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下
    2022-06-06
  • Vue使用Echarts實(shí)現(xiàn)排行榜效果

    Vue使用Echarts實(shí)現(xiàn)排行榜效果

    這篇文章主要為大家詳細(xì)介紹了Vue使用Echarts實(shí)現(xiàn)排行榜效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03

最新評(píng)論