// myComponents/scrollView/scrollView.js Component({ /** * 组件的属性列表 */ properties: { customStyle:{ type:String, value:"height: 100px;" }, threshold:{ type:Number, value:100 }, triggered:{ type:Boolean, value:false }, hasMore:{ type:Boolean, value:true }, load:{ type:Boolean, value:false } }, /** * 组件的初始数据 */ data: { show:false, scrollHeight:0, scrollTop: 0, threshold2: 50 }, attached:function(){ // const query = wx.createSelectorQuery().in(this); // query.select('.scroll-view-class').boundingClientRect(rect => { // this.setData({ // scrollHeight: rect.height // }); // }).exec(); }, /** * 组件的方法列表 */ methods: { onRefresh(){ this.triggerEvent('onRefresh') }, handleScroll(e) { if (this.data.scrollHeight && this.data.scrollTop) { const distanceToBottom = this.data.scrollHeight - this.data.scrollTop - window.innerHeight; if (distanceToBottom <= this.data.threshold2) { // 触发加载更多数据的操作 return true } } return false }, loadMore(e){ // this.setData({ // scrollTop: e.detail.scrollTop // }); // var a = this.handleScroll() // if(!a){ // return // } if(this.properties.triggered){ return } if(this.data.hasMore){ this.triggerEvent('loadMore') return } this.setData( { show:true } ) // wx.showToast({ // title: '没有更多了', // }) var self = this setTimeout(function () { self.setData({ show: false, }) }, 1000); } }, })