vue 使用iView組件中的Table實現(xiàn)定時自動滾動效果
封裝Table
要在css中設(shè)置table的高度,使數(shù)據(jù)過多時出現(xiàn)滾動條,將縱向設(shè)置為overflow-y: auto;橫向設(shè)置隱藏 overflow-x: hidden;
<template>
<div class="table_container">
<Table :loading="tableLoading" :columns="columns" :data="dataList" ref="tableL"></Table>
</div>
</template>
<script>
export default {
name: "tableList",
props: {
columns: {
type: Array,
default: () => []
},
dataList: {
type: Array,
default: () => []
},
},
data () {
return {
showContentHeight: 0,
tableBodyHeight: 0,
tableLoading: false,
}
},
methods: {
//動態(tài)滾動
dynamicScroll() {
let that = this
this.$nextTick(() => {
clearInterval(this.timer)
const table = this.$refs.tableL;
let tableBody = table.$el.__vue__.$refs.body;
if (tableBody) {
let showContentHeight = tableBody.offsetHeight;
let tableBodyHeight = tableBody.scrollHeight;
that.showContentHeight = showContentHeight
that.tableBodyHeight = tableBodyHeight
if(tableBodyHeight > showContentHeight) {
that.timerScroll()
}
}
});
},
//定時滾動
timerScroll() {
let that = this
const tmpTimer = setInterval(() => {
const table = that.$refs.tableL;
let tableBody = table.$el.__vue__.$refs.body;
if (tableBody) {
let canScrollHeight = that.tableBodyHeight - that.showContentHeight
let scrollTop = tableBody.scrollTop
console.log('scrollTop', scrollTop)
scrollTop += that.showContentHeight;
if(scrollTop > canScrollHeight) {
scrollTop = canScrollHeight
}
tableBody.scrollTop = scrollTop;
}
}, 5 * 1000);
this.timer = tmpTimer
this.$once("hook:beforeDestroy", () => {
clearInterval(tmpTimer);
});
}
},
}
</script>
<style scoped lang="less">
.table_container {
height: 100%;
}
.table_container /deep/ .ivu-table-wrapper {
height: 100%;
border: none;
border-bottom: 0;
border-right: 0;
}
.table_container /deep/ .ivu-table-body {
height: calc(100% - 40px); //減掉表頭的高度
overflow-x: hidden;
overflow-y: auto;
}
.table_container /deep/ .ivu-table-column-center {
background-color: #39698D;
color: white;
}
.table_container /deep/ tbody .ivu-table-column-center {
color: #89D5EA;
}
.table_container /deep/ .ivu-table {
background-color:rgba(255,255,255, 0);
color: #89D5EA;
}
.table_container /deep/ .ivu-table td {
background-color:rgba(255,255,255, 0);
border-bottom: 1px solid #496893;
}
.table_container /deep/ .ivu-table-tip {
color: #89D5EA;
}
.table_container /deep/ .ivu-table:before,.table_container /deep/ .ivu-table:after {
background-color: rgba(255,255,255, 0);
}
.table_container /deep/ .ivu-table th {
border-bottom: none;
}
/** .ivu-table-body 滾動條樣式*/
.table_container /deep/ .ivu-table-body::-webkit-scrollbar {
/*滾動條整體樣式*/
width: 5px; /*高寬分別對應(yīng)橫豎滾動條的尺寸*/
height: 3px;
}
.table_container /deep/ .ivu-table-body::-webkit-scrollbar-thumb {
/*滾動條里面小方塊*/
border-radius: 10px;
height: 20px;
-webkit-box-shadow: inset 0 0 5px black;
}
.table_container /deep/ .ivu-table-body::-webkit-scrollbar-track {
/*滾動條里面軌道*/
-webkit-box-shadow: inset 0 0 5px #6B90B6;
border-radius: 10px;
background: #ffffff;
}
</style>在引用組件的頁面調(diào)用定時滾動方法
<template>
<div class="layout">
<table-list ref="tableList" :columns="columns" :data-list="warehouseList"/>
</div>
</template>
<script>
import { columns } from './config'
import tableList from "@/components/tableList";
export default {
name: "board",
components: {
tableList,
},
data () {
return {
columns,
warehouseList: [],
resultData: {},
}
},
mounted() {
this.getData()
},
methods: {
getData() {
getWarehouseList({}).then(res => {
console.log('getWarehouseList', res)
if(res.success) {
this.resultData = res.result
this.warehouseList = res.result.warehouseList
const tableList = this.$refs.tableList;
//動態(tài)滾動
tableList.dynamicScroll()
}
})
}
}
}
</script>
<style scoped lang="less">
.layout {
width: 100%;
height: 100%;
background:url("../../../assets/prod_board.png") no-repeat center -2px;
background-size: 100% 100%;
color: #fff;
}
</style>到此這篇關(guān)于vue 使用iView組件中的Table實現(xiàn)定時自動滾動的文章就介紹到這了,更多相關(guān)vue Table定時自動滾動內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue3應(yīng)用elementPlus table并滾動顯示問題
- vue3?el-table結(jié)合seamless-scroll實現(xiàn)表格數(shù)據(jù)滾動的思路詳解
- vue中el-table兩個表尾合計行聯(lián)動同步滾動條實例代碼
- vue中獲取滾動table的可視頁面寬度調(diào)整表頭與列對齊(每列寬度不都相同)
- vue elementUI table表格數(shù)據(jù) 滾動懶加載的實現(xiàn)方法
- vue element-ui table表格滾動加載方法
- vue iview 隱藏Table組件里的某一列操作
- Vue基于iview table展示圖片實現(xiàn)點擊放大
- 淺談vue的iview列表table render函數(shù)設(shè)置DOM屬性值的方法
相關(guān)文章
vue.js iview打包上線后字體圖標(biāo)不顯示解決辦法
這篇文章主要介紹了vue.js iview打包上線后字體圖標(biāo)不顯示解決辦法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-01-01
解決ant-design-vue中menu菜單無法默認(rèn)展開的問題
這篇文章主要介紹了解決ant-design-vue中menu菜單無法默認(rèn)展開的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-10-10
使用Vue純前端實現(xiàn)發(fā)送短信驗證碼并實現(xiàn)倒計時
在實際的應(yīng)用開發(fā)中,涉及用戶登錄驗證、密碼重置等場景時,通常需要前端實現(xiàn)發(fā)送短信驗證碼的功能,以提升用戶體驗和安全性,以下是一個簡單的前端實現(xiàn),演示了如何在用戶點擊發(fā)送驗證碼按鈕時觸發(fā)短信驗證碼的發(fā)送,并開始一個倒計時2024-04-04
vue中手動封裝iconfont組件解析(三種引用方式的封裝和使用)
這篇文章主要介紹了vue中手動封裝iconfont組件(三種引用方式的封裝和使用),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09
微信小程序?qū)崙?zhàn)基于vue2實現(xiàn)瀑布流的代碼實例
瀑布流,又稱瀑布流式布局,是比較流行的一種網(wǎng)站頁面布局,視覺表現(xiàn)為參差不齊的多欄布局,隨著頁面滾動條向下滾動,這種布局還會不斷加載數(shù)據(jù)塊并附加至當(dāng)前尾部,這篇文章主要介紹了微信小程序?qū)崙?zhàn),基于vue2實現(xiàn)瀑布流,需要的朋友可以參考下2022-12-12

