0.0.30 • Published 2 years ago
miniprogram-infinitescroll v0.0.30
miniprogram-infinitescroll
小程序 mobx composition 下拉加载
Usage
TODO
Options
TODO
Development
LICENSE
MIT
<view style="margin-bottom: 50rpx;display: flex;">
<!-- id名对应表单字段名 -->
<input
id="keywords"
bindinput="change"
value="{{values.keywords}}"
style="border: solid 1px ;height:80rpx;flex: 6;"
/>
<button bindtap="search" style="flex: 1;">搜索</button>
<button bindtap="reset" style="flex:1;">重置</button>
</view>
<view wx:if="{{loading}}"> 载入中 </view>
<view wx:elif="{{error}}"> 载入出错 </view>
<view wx:else>
<scroll-view
bindscrolltolower="bindscrolltolower"
style="max-height: 1000rpx;"
lower-threshold="{{200}}"
scroll-y
>
<view>
<view style="margin-bottom: 50rpx;" wx:for="{{data.list}}">
<view style="margin-bottom: 20rpx;">
<text>{{item.name}}</text>
</view>
</view>
</view>
</scroll-view>
<view wx:if="{{noMore}}">
{{ data.list.length ? '共'+data.list.length+'条,没有更多了' :
'没有相关数据'}}
</view>
<view wx:elif="{{errorMore}}"> 加载更多出错 </view>
<view wx:elif="{{loadingMore}}"> 加载更多中 </view>
<view style="float: right;">
<button loading="{{loadMore}}" bindtap="loadMore">手动点击加载更多</button>
</view>
</view>
//搜索下拉列表
import { useForm, useSearchInfiniteScroll } from 'miniprogram-infinitescroll';
import { compositionApi } from 'miniprogram-composition';
const getData = ({ current, pageSize }, formData) => {
return new Promise((resolve, reject) => {
wx.request({
url: 'http://cloud-music.pl-fe.cn/search',
data: {
limit: pageSize,
offset: (current - 1) * pageSize,
...formData,
},
success: (res) => resolve(res.data),
fail: reject,
});
});
};
Component({
behaviors: [compositionApi],
setup() {
const form = useForm({
keywords: '红颜如霜',
});
const { values, change, setValues, reset: resetValues } = form;
const {
loadMore,
loadMoreAsync, //返回promise的加载更多
bindscrolltolower,
data,
loading,
loadingMore,
error,
errorMore,
noMore,
search,
searchAysnc, //返回promise的搜索
reset,
} = useSearchInfiniteScroll(
async ({ current, pageSize }, formData) => {
const res = await getData({ current, pageSize }, formData);
return {
list: res.result.songs,
total: res.result.songCount,
};
},
{
form,
defaultPageSize: 20,
},
);
return {
error, //出错
errorMore, //加载更多出错
values, //表单值
change, //表单变化事件
loadMore, //载入更多
search, //搜索
reset, //重置
noMore, //是否没有更多数据了
data, //列表数据
loading, //加载中
loadingMore, //加载更多中
bindscrolltolower, //下拉事件
};
},
});
0.0.30
2 years ago
0.0.24
2 years ago
0.0.25
2 years ago
0.0.26
2 years ago
0.0.27
2 years ago
0.0.28
2 years ago
0.0.29
2 years ago
0.0.23
2 years ago
0.0.22
2 years ago
0.0.21
2 years ago
0.0.20
2 years ago
0.0.19
2 years ago
0.0.18
2 years ago
0.0.16
2 years ago
0.0.15
2 years ago
0.0.14
2 years ago
0.0.13
2 years ago
0.0.12
2 years ago
0.0.11
2 years ago
0.0.10
2 years ago
0.0.9
2 years ago
0.0.8
2 years ago
0.0.7
2 years ago
0.0.6
2 years ago
0.0.5
2 years ago
0.0.4
2 years ago
0.0.3
2 years ago
0.0.2
2 years ago
0.0.1
2 years ago