<template>
<Table width="550" height="200" border :columns="columns2" :data="data4"></Table>
</template>
<script>
export default {
data () {
return {
columns2: [
{
title: 'Name',
key: 'name',
width: 100,
fixed: 'left'
},
{
title: 'Age',
key: 'age',
width: 100
},
{
title: 'Province',
key: 'province',
width: 100
},
{
title: 'City',
key: 'city',
width: 100
},
{
title: 'Address',
key: 'address',
width: 200
},
{
title: 'Postcode',
key: 'zip',
width: 100
},
{
title: 'Action',
key: 'action',
fixed: 'right',
width: 120,
render: (h, params) => {
return h('div', [
h('Button', {
props: {
type: 'text',
size: 'small'
}
}, 'View'),
h('Button', {
props: {
type: 'text',
size: 'small'
}
}, 'Edit')
])
}
}
],
data4: [
{
name: 'John Brown',
age: 18,
address: 'New York No. 1 Lake Park',
province: 'America',
city: 'New York',
zip: 100000
},
{
name: 'Jim Green',
age: 24,
address: 'Washington, D.C. No. 1 Lake Park',
province: 'America',
city: 'Washington, D.C.',
zip: 100000
},
{
name: 'Joe Black',
age: 30,
address: 'Sydney No. 1 Lake Park',
province: 'Australian',
city: 'Sydney',
zip: 100000
},
{
name: 'Jon Snow',
age: 26,
address: 'Ottawa No. 2 Lake Park',
province: 'Canada',
city: 'Ottawa',
zip: 100000
},
{
name: 'John Brown',
age: 18,
address: 'New York No. 1 Lake Park',
province: 'America',
city: 'New York',
zip: 100000
},
{
name: 'Jim Green',
age: 24,
address: 'Washington, D.C. No. 1 Lake Park',
province: 'America',
city: 'Washington, D.C.',
zip: 100000
},
{
name: 'Joe Black',
age: 30,
address: 'Sydney No. 1 Lake Park',
province: 'Australian',
city: 'Sydney',
zip: 100000
},
{
name: 'Jon Snow',
age: 26,
address: 'Ottawa No. 2 Lake Park',
province: 'Canada',
city: 'Ottawa',
zip: 100000
}
]
}
},
mounted () {
// 表格滚动的节点class dom.scrollTop 当前节点滚动条距离顶部的距离为0就在顶部 dom.scrollHeight 当前滚动内容得高度
// dom.clientHeight 当前节点可视窗口的高度
let dom = document.querySelector('.ivu-table-body')
console.log(dom.addEventListener, dom.scrollHeight, dom.scrollTop, dom.clientHeight)
const that = this
dom.addEventListener('scroll', function () {
// scrollDistance 为零时滚动到底部
const scrollDistance = dom.scrollHeight - dom.scrollTop - dom.clientHeight
console.log(scrollDistance, '------', dom.scrollHeight, dom.scrollTop, dom.clientHeight)
if (scrollDistance <= 0) { // 等于0证明已经到底,可以请求接口
const data = JSON.parse(JSON.stringify(that.data4))
that.data4 = data.concat([{
name: 'Joe Black',
age: 30,
address: 'Sydney No. 1 Lake Park',
province: 'Australian',
city: 'Sydney',
zip: 100000
},
{
name: 'Jon Snow',
age: 26,
address: 'Ottawa No. 2 Lake Park',
province: 'Canada',
city: 'Ottawa',
zip: 100000
}])
}
})
}
}
</script>
vue iview-design table 实现滚动加载数据
最新推荐文章于 2024-06-06 14:59:16 发布