1.pages.json中开启"enablePullDownRefresh": true
{
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"style": {
"navigationBarTitleText": "uni-app",
"enablePullDownRefresh": true
}
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "uni-app",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
}
}
2.监听下拉刷新时间
<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();
})
}
}
</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>