封装table
要在css中设置table的高度,使数据过多时出现滚动条,将纵向设置为overflow-y: auto;横向设置隐藏 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: {
//动态滚动
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; /*高宽分别对应横竖滚动条的尺寸*/
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>在引用组件的页面调用定时滚动方法
<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;
//动态滚动
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>到此这篇关于vue 使用iview组件中的table实现定时自动滚动的文章就介绍到这了,更多相关vue table定时自动滚动内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论