效果:
代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div{
width: 400px;
height: 500px;
border: 2px solid black;
margin: 100px auto;
overflow: scroll;
}
span{
display: inline-block;
background: rgb(20, 148, 233);
margin-top: 10px;
margin-left: 15px;
padding: 3px 12px;
}
</style>
</head>
<body>
<div id="app">
<span v-for="item in data.slice(0,showNum)">{{item}}</span>
</div>
</body>
<script src="./vue/vue.min.js"></script>
<script>
new Vue({
el: '#app',
data(){
return{
data:['sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq','sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq',
'sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq','sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq',
'sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq','sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq',
'sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq','sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq',
'sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq','sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq',
'sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq','sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq',
'sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq','sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq',
'sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq','sad','sdf','jgsdfh','sfg','qwe','blink','aoe','ntr','asd','aaa','fgnb','fgsb','qqq','vt','qe','aeqrq'],
showNum: 80
}
},
mounted(){
let _this = this;
document.querySelector('div').onscroll = function(){
if((this.scrollHeight - this.scrollTop )== this.clientHeight){
_this.showNum += 20;
}
}
}
})
</script>
</html>