123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- // 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.data.hasMore){
- this.triggerEvent('loadMore')
- return
- }
- this.setData(
- {
- show:true
- }
- )
- // wx.showToast({
- // title: '没有更多了',
- // })
- var self = this
- setTimeout(function () {
- self.setData({
- show: false,
- })
- }, 2000);
- }
- },
- })
|