页面内容太多分步加载,用js和vue实现滚动条下拉加载功能
作者:互联网
效果:
代码
<!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>
标签:fgsb,vue,jgsdfh,js,vt,asd,sfg,blink,加载 来源: https://blog.csdn.net/WanweI897/article/details/121317749