dm-wechat-mini/components/listView/index.js
2025-02-22 03:14:42 +08:00

79 lines
1.5 KiB
JavaScript

// components/listView/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
"bindrefresherrefresh":{
type:Function
},
"refresherTriggered":{
type:Boolean,
value:false
},
height:0,
loadMoreText:{
type:String,
value:'已经到底了'
},
showLoadMore:{
type:Boolean,
value:true
},
loadAll:{
type:Boolean,
value:false
},
class:{
type:String,
value:''
}
},
/**
* 组件的初始数据
*/
data: {
heightStyle:'',
scrollHeight:0
},
lifetimes:{
attached(){
this.createSelectorQuery().select('#scrollView').boundingClientRect((res)=>{
this.data.scrollHeight = res.height;
}).exec();
const windowInfo = wx.getWindowInfo();
}
},
/**
* 组件的方法列表
*/
methods: {
refreshList(){
this.triggerEvent('refresh');
},
scrolling(event){
//scrollTop scrollHeight
const bottomHeight = event.detail.scrollHeight-event.detail.scrollTop-this.data.scrollHeight;
if(bottomHeight<100){
this.triggerEvent('loadMore');
}
}
},
observers:{
height(h){
let heightStyle = '';
if(h){
if(typeof h == 'string'){
heightStyle = `height:${h}`
}else{
heightStyle = `height:${this.properties.height*2}rpx`
}
this.setData({
heightStyle:heightStyle
})
}
}
}
})