uniapp上拉加载

1.pages.json中开启触底距离  "onReachBottomDistance":

{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
			"path": "pages/index/index",
			"style": {
				"navigationBarTitleText": "uni-app",
				"enablePullDownRefresh": true,
				"onReachBottomDistance":100
			}
		}
	],
	"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "uni-app",
		"navigationBarBackgroundColor": "#F8F8F8",
		"backgroundColor": "#F8F8F8"
	}
}

2.页面中监听事件onReachBottom

<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
		<view v-for="item in list">
			{{item}}
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: 'Hello',
				list: ['UI','前端','后端','测试','运维','前端','后端','测试','运维','前端','后端','测试','运维','前端','后端','测试','运维','前端','后端','测试','运维','前端','后端','测试','运维','前端','后端','测试','运维','前端','后端','测试','运维']
			}
		},
		onLoad() {

		},
		methods: {

		},
		onPullDownRefresh() {
			console.log("触发了下拉刷新")
			setTimeout(()=>{
				this.list = ['云计算','大数据','人工智能','区块链'];
				uni.stopPullDownRefresh();
			})
		},
		onReachBottom() {
			console.log('页面触底了')
			// 一般用于加载下一页数据
			this.list = [...this.list, ...['云计算','大数据','人工智能','区块链']]
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>

 

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页