uniapp项目中 实现上拉加载、下拉刷新
需下载uniapp插件: uni-load-more 加载更多
组件名:uni-load-more 用于列表中,做滚动加载使用,展示 loading 的各种状态
效果:
1.在需要实现效果的配置文件pages.json中添加代码:enablePullDownRefresh":true
{
"path" : "pages/myappointmentmodule/index",
"style" :
{
"navigationBarTitleText" : "我的预约",
"enablePullDownRefresh":true
}
},
2.页面内容
<view v-if="isLoadMore">
<uni-load-more iconType="circle" :status="loadStatus" ></uni-load-more>
</view>
3.js代码
export default {
data() {
return {
page: 1,
limit: 10,
sort: 'starttime-desc',
appUser: '',
authority: 'STUDENT',
schoolAcademy: '0001',
reservList: [],
loadStatus: 'noMore',
isLoadMore: false,
};
},
onLoad() {
this.getList()
uni.removeStorageSync('detail')
},
methods: {
navToDetail(item) {
uni.setStorageSync('detail',item)
uni.navigateTo({
url: '../myappointmentdetail/index?id='+item.uid
})
},
getList() {
const params = {
page: this.page,
limit: this.limit,
sort: this.sort,
appUser: uni.getStorageSync('userInfo').username,
authority: this.authority,
schoolAcademy: this.schoolAcademy,
}
this.$api.getReservation(params).then(res => {
console.log(res, '预约列表')
if (res.code == 0) {
const data = res.data
if (data.length != 0) {
this.reservList = this.reservList.concat(data)
if (data.length < this.limit) {
this.isLoadMore = true
this.loadStatus = 'noMore'
} else {
this.isLoadMore = false
}
} else {
this.isLoadMore = true
this.loadStatus = 'noMore'
}
} else {
this.$Common.tipMsg(res.msg)
}
})
},
onReachBottom() {
if (!this.isLoadMore) {
this.isLoadMore = true
this.page++
this.getList()
}
},
onPullDownRefresh() {
this.reservList = []
this.page = 1
this.getList()
uni.stopPullDownRefresh()
}
}
}