uni-app之下拉刷新与 上拉加载
uni-app之下拉刷新
- 需要 在 page.json 文件之中 的对应的 page之中 设置
"enablePullDownRefresh":true, - 方法1:
- 方法2:
- uni.startPullDownRefresh() 自定义按钮事件,触发这个下拉刷新
- 关闭下拉刷新
uni.stopPullDownRefresh()
page.json
- 再对应的 页面之中 新增
"enablePullDownRefresh":true,
{
"pages": [
{
"path": "pages/msg/msg",
"style":{
"navigationBarTitleText":"我是msg",
"navigationBarBackgroundColor": "#007aff",
"enablePullDownRefresh":true,
"h5":{
"pullToRefresh":{
"color":"#DD524D"
}
}
}
},
{
"path": "pages/index/index"
}
],
}
方式1 使用配置项的 形式开启下拉刷新
页面 msg.vue
<template>
<view>
我是msg之list
<view v-for="(item,index) in list" :key="index">
<view class="">{{ item }}</view>
</view>
</view>
</template>
<script>
export default {
data(){
return {
list:[
"语文","数学","英语","美术","生物"
]
}
},
onPullDownRefresh(){
console.log("下拉刷新的");
setTimeout(()=>{
this.list = ["语文1","数学2","英语3","美术4","生物5"]
uni.stopPullDownRefresh();
},2000)
}
}
</script>
方式2 自定义按钮事件 触发 uni.startPullDownRefresh()
<template>
<view>
我是msg之list
<view v-for="(item,index) in list" :key="index">
<view class="">{{ item }}</view>
</view>
<button type="default" @click="refreshBtn">我是下拉刷新</button>
</view>
</template>
<script>
export default {
data(){
return {
list:[
"语文","数学","英语","美术","生物"
]
}
},
methods: {
refreshBtn(){
uni.startPullDownRefresh("success")
setTimeout(()=>{
this.list = ["语文1","数学2","英语3","美术4","生物5"]
uni.stopPullDownRefresh();
},2000)
}
}
}
</script>
<style lang="scss">
</style>
uni-app之上拉加载 ( 页面触底 )
page.json 配置
- 页面触底的距离 触发
"onReachBottomDistance":100,
{
"pages": [
{
"path": "pages/msg/msg",
"style":{
"navigationBarTitleText":"我是msg",
"navigationBarBackgroundColor": "#007aff",
"onReachBottomDistance":100,
}
},
]
}
msg.vue 使用 页面触底 生命函数 onReachBottom
<template>
<view>
我是msg之list
<view class="box" v-for="(item,index) in list" :key="index">
<view class="box-item">{{ item }}</view>
</view>
</view>
</template>
<script>
export default {
data(){
return {
list:[
"语文","数学","英语","美术","生物","物理","化学","品德",
"道法","刀法","菜鸡","龙龙","非法","朗朗","花花","屁屁"
]
}
},
onReachBottom(){
this.list = [...this.list,...["小小","渣渣","亮亮"]]
},
methods: {
}
}
</script>
<style lang="scss">
.box {
&-item {
height: 50px;
line-height: 50px;
border-bottom: 1px solid #ccc;
}
}
</style>
|