首頁 > 軟體

element-ui卷軸el-scrollbar置底方式

2022-08-01 18:03:47

element-ui卷軸el-scrollbar置底

在需要捲動的地方加上

<el-scrollbar ref="myScrollbar"  style="height: 600px"></el-scrollbar>

方法

 scrollDown() {
        this.$refs['myScrollbar'].wrap.scrollTop = this.$refs['myScrollbar'].wrap.scrollHeight
 }

不能在接收資料時呼叫,需要在頁面渲染結束時呼叫方法

updated: function() {
      this.scrollDown()
    }

element-ui表格卷軸樣式el-scrollbar使用問題

實現效果:

問題如下圖,原始表格卷軸很醜

想要的效果如下

操作步驟

1、template部分程式碼

<template>
<!-- 外面的最大的父容器盒子 -->
  <div class="ccc">
    <!-- 使用el-scrollbar標籤的效果 -->
    <div class="box">
      <!-- 隱藏標籤scrollbar包住所有捲動內容 -->
      <el-scrollbar>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="date" label="日期" width="180">
          </el-table-column>
          <el-table-column prop="name" label="姓名" width="180">
          </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
        </el-table>
      </el-scrollbar>
    </div>
    <!-- 沒有使用el-scrollbar標籤普通容器效果 -->
    <div class="box2">
      <el-table :data="tableData" style="width: 100%">
          <el-table-column prop="date" label="日期" width="180">
          </el-table-column>
          <el-table-column prop="name" label="姓名" width="180">
          </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
          <el-table-column prop="address" label="地址" width="480"> </el-table-column>
        </el-table>
    </div>
  </div>
</template>

2、script資料部分的程式碼

<script>
export default {
  // 資料
  data () {
    return {
      tableData: [
        {
          date: '2016-05-02',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1518 弄'
        },
        {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1517 弄'
        },
        {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1519 弄'
        },
        {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1516 弄'
        },
        {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1517 弄'
        },
        {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1519 弄'
        },
        {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1517 弄'
        },
        {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1519 弄'
        },
        {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1516 弄'
        },
        {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1517 弄'
        },
        {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1519 弄'
        },
        {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1516 弄'
        },
        {
          date: '2016-05-04',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1517 弄'
        },
        {
          date: '2016-05-01',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1519 弄'
        },
        {
          date: '2016-05-03',
          name: '王小虎',
          address: '上海市普陀區金沙江路 1516 弄'
        }
      ]
    }
  }
}
</script>

3、css樣式部分程式碼

<style>
.ccc .box {
  width: 100%;
  height: 400px;
  border: 1px solid red;
  margin: 0 auto;
  white-space: nowrap;
}
.ccc .el-scrollbar {
  height: 100%;
}
.ccc .box2 {
  margin-top: 50px;
  height: 200px;
  overflow: overlay;
}
  /* 最為關鍵得兩個樣式程式碼,可以設定全域性卷軸樣式,也可以按需設定 */
  .ccc ::-webkit-scrollbar {
  /* 設定豎向卷軸的寬度 */
  width: 5px;
  /* 設定橫向卷軸的高度 */
  height: 5px;
}
.ccc ::-webkit-scrollbar-thumb {
  /*卷軸的背景色*/
  background-color: rgba(144,147,153,.3);
  border-radius: 35px;
  position: relative;
}
</style>

以上為個人經驗,希望能給大家一個參考,也希望大家多多支援it145.com。


IT145.com E-mail:sddin#qq.com