vue实现滚动到底部加载

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<script>
import debounce from 'lodash/debounce'
export default {
props: {
loading: {
type: Boolean,
default: false,
},
loadmore: {
type: String,
default: '',
},
},
data() {
return {}
},
methods: {
onScroll() {
const tar = this.$refs.scroll
const { scrollHeight: sh, clientHeight: ch, scrollTop: st } = tar
if (sh === ch + st) {
this.$emit('toLower')
this.$nextTick(() => {
debounce(() => {
tar.scrollTop = sh - ch - 1
}, 500)()
})
}
},
},
}
</script>
<template>
<div class="comp-scroll">
<div class="scroll-wrap" ref="scroll" @scroll="onScroll">
<slot />
</div>
<div class="loadmore flx-c pt5">
<a-spin v-show="loading" />
<span v-show="!loading">{{ loadmore }}</span>
</div>
</div>
</template>
<style lang="scss" scoped>
.comp-scroll {
height: 100%;
width: 100%;
}
.scroll-wrap {
height: calc(100% - 30px);
width: 100%;
color: white;
overflow: hidden scroll;
}
.scroll-wrap::-webkit-scrollbar {
width: 0;
}
/deep/ .ant-spin-dot-item {
background-color: #fff !important;
}
.loadmore {
position: absolute;
z-index: 1000;
width: 100%;
text-align: center;
}
</style>