ScrollView

ScrollView 加载更多的 ScrollView

一般配合 BfScrollView.useListHook 使用

代码示例

import { BfScrollView, BfTabs } from '@bud-fe/react-taro-ui';
import { View } from '@tarojs/components';
import React, { useEffect, useState } from 'react';
export default () => {
const [queryProps, setQueryProps] = useState<Record<string, any>>({
pageNo: 1,
pageSize: 10,
});
const { reLoadDataWithProps, ...scrollViewProps } = BfScrollView.useListHook({
loadData,
queryProps,
});
useEffect(() => {
reLoadDataWithProps(queryProps);
}, [queryProps]);
async function loadData(params) {
console.log('loadData ---> ', params);
setTimeout(() => null, 2000);
return { code: 200, data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] };
}
return (
<>
<BfScrollView
{...scrollViewProps}
renderListItem={(item, index) => (
<View style={{ padding: '20px', borderTop: '1px solid #333' }}>{`${item}-${index}`}</View>
)}
header={
<BfTabs
current={1}
tabs={[
{ label: 'aaa', value: 1 },
{ label: 'bbb', value: 2 },
{ label: 'ccc', value: 3 },
]}
/>
}
footer={<View>我是尾部</View>}
/>
</>
);
};

API

BfScrollView

属性名描述类型默认值
renderListItem每个Item项的渲染逻辑(data: any, index: any) => any(必选)
customEmptyView搜索结果为空时展示any<BfEmptyView />
defaultView未执行搜索时默认展示any--
dataList列表数据any[](必选)
_loadData滚动到底部/右边,会发起请求(params: any) => Promise<any>(必选)
reloadWithError加载失败时,点击的回调() => void(必选)
header头部any--
footer尾部any--
scrollViewClass传给scroll-view类名string''
scrollViewPropsScrollViewProps {@link ScrollViewProps}ScrollViewProps--
loading是否显示加载中booleanfalse
isFinished是否显示加载完成booleanfalse
error是否显示加载失败booleanfalse

useListHook

属性名描述类型默认值
loadData加载数据(params: any) => Promise<any>(必选)
queryProps请求的参数Record<string, any>--
autoLoad挂载时是否自动加载booleanfalse
pageNoPropspageNo 的字段名stringpageNo
pageSizePropspageSize 的字段名stringpageSize
disablePaging禁用分页加载booleanfalse
successGroups加载成功的 code 集合number[][200, 200000]
dumi10:24