可滚动视图区域。用于区域滚动。
具体使用可以参考 scroll-view | uni-app官网
1.template部分
<scroll-view scroll-y="true" class="scrollbox" :scroll-top="scrollTop" @scrolltolower="loadMore">
// 这里没有数据时 我是用了一个封装的组件
<empty-tips class="noData" v-if='list&&list.length==0' :tips-list="['暂无数据']" />
// 这里是列表
<view class="item" v-else>
<view v-for="(item,index) in list" :key="index">
</view>
</view>
</scroll-view>
2.script部分
loadMore() {
console.log('触底了')
// 判断需不需要加载列表
if(this.current*this.size<this.total){
this.current++;
this.commanderInfo(false);
} else {
console.log('没有最新啦')
}
},
commanderInfo(isInit=true) {
if (isInit) {this.current = 1}
wx.showLoading();
http.request({
url: '这里是接口地址',
method: 'get',
data: {
size: this.size,
current: this.current,
},
callBack: (res) => {
this.total = res.total
if (this.current == 1)
this.list= [];
wx.hideLoading();
this.rescord = res
const list = res.records
this.list= this.list.concat(list)
}
})
}
3.css部分
这列需要设置高度,一开始我没有设置高度 触底没有作用
.scrollbox {
height: calc(100vh - 600rpx);
overflow: auto;
}