mint ui : loadmore上拉刷新下拉加载

< template>
< div id= "app">
< mt-loadmore :top-method="loadTop" :bottom-method="loadBottom" :bottom-all-loaded="allLoaded" :max-distance=" 150"
@top-status-change="handleTopChange" ref= "loadmore">

< div slot= "top" class= "mint-loadmore-top">
< span v-show="topStatus === 'pull'" :class="{ 'rotate': topStatus === 'drop' }">↓</ span>
< span v-show="topStatus === 'loading'">Loading...</ span>
< span v-show="topStatus === 'drop'">释放更新</ span>
</ div>

< ul class= "scroll-wrapper">
< li v-for="(item,index) in list" :key="index">{{ item }}</ li>
</ ul>

< div v-if="allLoaded">
没有更多了
</ div>

</ mt-loadmore>
</ div>
</ template>
< script>
import {Loadmore} from 'mint-ui';

export default {
data() {
return {
list: [],
allLoaded: false,
topStatus: ''
};
},
created: function () {
for ( let i = 0; i < 20; i ++){
this.list. push( 'demo' + i);
}

},
methods: {
loadTop: function () { // 刷新数据的操作
this.allLoaded = false;
setTimeout(() =>{
this.list. splice( 0, this.list.length);
let len = 20;
for ( let i = 0; i < len; i ++){
this.list. push( 'demo' + i);
}
this.$refs.loadmore. onTopLoaded();
}, 2000);
},
loadBottom: function () { // 加载更多数据的操作
//load data
console. log( this.list.length)
if( this.allLoaded){
return;
}
setTimeout(() =>{
let len = 10;
for ( let i = 0; i < len; i ++){
this.list. push( 'dddd' + i);
}

if( this.list.length > 40){
this.allLoaded = true; // 若数据已全部获取完毕
}
this.$refs.loadmore. onBottomLoaded();
}, 2000);

},
handleTopChange: function ( status) {
this.topStatus = status;
}
}
};
</ script>
< style>
*{
margin: 0;
padding: 0;
}
html, body{
height: 100 %;
}

#app{

height: 100 %;
overflow: scroll;
}
.scroll-wrapper{
margin: 0;
padding: 0;
list-style: none;

}
.scroll-wrapper li{
line-height: 120 px;
font-size: 60 px;
text-align: center;
}
</ style>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值