# uni.startPullDownRefresh(options?)

开始下拉刷新

# # Parameters

name type required default description
options StartPullDownRefreshOptions NO - -

# # StartPullDownRefreshOptions Values

name type optinal default description
success (result: AsyncApiSuccessResult) => void NO - 接口调用成功的回调函数
fail (result: PullDownRefreshError) => void NO - 接口调用失败的回调函数
complete (result: AsyncApiResult) => void NO - 接口调用结束的回调函数(调用成功、失败都会执行)
# # PullDownRefreshError Values
name type optinal default description
errCode number YES - 下拉刷新错误码 - 4: 框架内部异常
errSubject string YES - 统一错误主题(模块)名称
data any NO - 错误信息中包含的数据
errMsg string YES - -
# # AsyncApiResult Values
name type optinal default description
errMsg string YES - -

# # Return value

Type optinal
Promise<AsyncApiSuccessResult> NO

# # AsyncApiSuccessResult Values

name type optinal default description
errMsg string YES - -

# # See also

startPullDownRefresh

Related Bug

# uni.stopPullDownRefresh()

停止当前页面下拉刷新

使用:

  1. 首先pages.json里配置了页面可下拉刷新"enablePullDownRefresh": true
  2. 当用户下拉页面时触发页面生命周期onPullDownRefresh
  3. 在合适的时机(如联网刷新数据结束),调用本APIuni.stopPullDownRefresh(),结束下拉刷新状态

本API仅负责页面下拉刷新。如使用组件下拉刷新,另见scroll-view、list-view等组件的文档。

# # See also

stopPullDownRefresh

Related Bug

# # Example

hello uni-app x

<template>
   <scroll-view>
   	<!-- 实际开发中,长列表应该使用list-view -->
   	<view class="uni-padding-wrap uni-common-mt">
   		<text class="text" v-for="(num,index) in data" :key="index">list - {{num}}</text>
   		<view class="uni-loadmore" v-if="showLoadMore">{{loadMoreText}}</view>
   	</view>
   </scroll-view>
</template>
<script lang="uts">
   export default {
   	data() {
   		return {
   			data: [] as Array<number>,
   			loadMoreText: "加载中...",
   			showLoadMore: false,
   			max: 0
   		}
   	},
   	onLoad() {
   		this.initData();
   	},
   	onReachBottom() {
   		console.log("onReachBottom");
   		if (this.max > 40) {
   			this.loadMoreText = "没有更多数据了!"
   			return;
   		}
   		this.showLoadMore = true;
   		setTimeout(() => {
   			this.setListData();
   		}, 300);
   	},
   	onPullDownRefresh() {
   		console.log('onPullDownRefresh');
   		this.initData();
   	},
   	methods: {
   		initData(){
   			setTimeout(() => {
   				this.max = 0;
   				this.data = [];
   				let data:Array<number> = [];
   				this.max += 20;
   				for (let i:number = this.max - 19; i < this.max + 1; i++) {
   					data.push(i)
   				}
   				this.data = this.data.concat(data);
   				uni.stopPullDownRefresh();
   			}, 300);
   		},
   		setListData() {
   			let data:Array<number> = [];
   			this.max += 10;
   			for (let i:number = this.max - 9; i < this.max + 1; i++) {
   				data.push(i)
   			}
   			this.data = this.data.concat(data);
   		}
   	}
   }
</script>

<style>
   .text {
   	margin: 16rpx 0;
   	width:100%;
   	background-color: #fff;
   	height: 120rpx;
   	line-height: 120rpx;
   	text-align: center;
   	color: #555;
   	border-radius: 8rpx;
   }
</style>

# # General type

# # GeneralCallbackResult

name type optinal default description
errMsg string YES - 错误信息