File tree Expand file tree Collapse file tree 7 files changed +100
-8
lines changed
Expand file tree Collapse file tree 7 files changed +100
-8
lines changed Original file line number Diff line number Diff line change 55 <view class =" am-list-body" >
66 <slot />
77 </view >
8+ <view class =" am-list-load-more" a : if =" {{loadMore === 'load'}}" ><icon type =" loading" size =" 16" /><text class =" am-list-load-more-txt" >{{loadContent[0]?loadContent[0]:''}}</text ></view >
9+ <view class =" am-list-load-over" a : if =" {{loadMore === 'over'}}" >{{loadContent[1]?loadContent[1]:''}}</view >
810 <view class =" am-list-footer" a : if =" {{$slots.footer}}" >
911 <slot name =" footer" />
1012 </view >
Original file line number Diff line number Diff line change 1616 &-footer {
1717 padding : 8px 16px 16px 16px ;
1818 }
19+ &-load-more {
20+ text-align : center ;
21+ background : #fff ;
22+ padding : 10px 16px ;
23+ font-size : 15px ;
24+ line-height : 1.4 ;
25+ color : @color-text-title ;
26+ &-txt {
27+ padding : 0 10px ;
28+ }
29+ }
30+ &-load-over {
31+ display : block ;
32+ padding : 10px 16px ;
33+ font-size : 10px ;
34+ text-align : center ;
35+ color : #ccc ;
36+ text-shadow : 1px 1px #f0f0f0 ;
37+ }
1938}
Original file line number Diff line number Diff line change 1111| 属性名 | 描述 | 类型 | 默认值 |
1212| ---- | ---- | ---- | ---- |
1313| className | 自定义class | String| |
14+ | loadMore | 显示加载更多 item。` load ` :显示加载更多;` over ` :显示加载完成无更多 | String| |
15+ | loadContent | 需结合 ` loadMore ` 属性使用,用于文案展示 | Array | [ '加载更多...','-- 数据加载完了 --'] |
16+
17+ ### loadMore 使用介绍
18+ 当需要使用无限循环列表时,可将 ` list ` 组件放置入到 [ ` scroll-view ` ] ( https://docs.alipay.com/mini/component/scroll-view ) 中,根据需求对 [ ` scroll-view ` ] ( https://docs.alipay.com/mini/component/scroll-view ) 添加相对应的属性,比如:
19+ ``` xml
20+ <scroll-view style =" height: 80vh;" scroll-y onScrollToLower =" onScrollToLower" enable-back-to-top =" true" >
21+ <list loadMore =" {{loadMore}}" loadContent =" {{loadContent}}" >
22+ <list-item >...</list-item >
23+ </list >
24+ </scroll-view >
25+ ```
26+ ``` javascript
27+ Page ({
28+ data: {
29+ loadMore: ' ' ,
30+ loadContent: [
31+ ' 马不停蹄加载更多数据中...' ,
32+ ' -- 已经到底了,加不了咯 --' ,
33+ ],
34+ },
35+ onScrollToLower () {
36+ // 根据实际数据加载情况设定 loadMore 的值即可,分别为 load 和 over
37+ this .setData ({
38+ loadMore: ' load' ,
39+ })
40+ },
41+ })
42+ ```
1443
1544### slots
1645
Original file line number Diff line number Diff line change 11Component ( {
22 props : {
33 className : '' ,
4+ loadMore : false ,
5+ loadContent : [
6+ '' ,
7+ '' ,
8+ ] ,
9+ } ,
10+ data : {
11+ loadContent : [
12+ '加载更多...' ,
13+ '-- 数据加载完了 --' ,
14+ ] ,
15+ } ,
16+ didMount ( ) {
17+ const loadTxt = this . props . loadContent [ 0 ] ? this . props . loadContent [ 0 ] : this . data . loadContent [ 0 ] ;
18+ const overTxt = this . props . loadContent [ 1 ] ? this . props . loadContent [ 1 ] : this . data . loadContent [ 1 ] ;
19+ this . setData ( {
20+ loadContent : [ loadTxt , overTxt ] ,
21+ } ) ;
22+ } ,
23+ didUpdate ( ) {
24+ const loadTxt = this . props . loadContent [ 0 ] ? this . props . loadContent [ 0 ] : this . data . loadContent [ 0 ] ;
25+ const overTxt = this . props . loadContent [ 1 ] ? this . props . loadContent [ 1 ] : this . data . loadContent [ 1 ] ;
26+ this . setData ( {
27+ loadContent : [ loadTxt , overTxt ] ,
28+ } ) ;
429 } ,
530} ) ;
Original file line number Diff line number Diff line change 1515.am-list-sticky {
1616 position: sticky;
1717 top: 0;
18+ z-index: 2;
1819}
Original file line number Diff line number Diff line change 11<view >
2- <scroll-view style =" height: 80vh;" scroll-y onScrollToLower =" onScrollToLower" >
2+ <scroll-view style =" height: 80vh;" scroll-y onScrollToLower =" onScrollToLower" enable-back-to-top = " true " >
33 <list >
44 <view slot =" header" >
55 列表头部
143143 </list-item >
144144 </block >
145145 </list >
146- <list >
146+ <list loadMore = " {{loadMore}} " loadContent = " {{loadContent}} " >
147147 <view slot =" header" >
148148 无限滚动列表
149149 </view >
166166 </view >
167167 </list-item >
168168 </block >
169- <view slot =" footer" >
170- 列表尾部
171- </view >
172169 </list >
173170 </scroll-view >
174171</view >
Original file line number Diff line number Diff line change @@ -228,17 +228,36 @@ Page({
228228 align : 'middle' ,
229229 } ,
230230 ] ,
231+ loadMore : '' ,
232+ loadContent : [
233+ '马不停蹄加载更多数据中...' ,
234+ '-- 已经到底了,加不了咯 --' ,
235+ ] ,
236+ maxList : 5 ,
231237 } ,
232238 onItemClick ( ev ) {
233239 my . alert ( {
234240 content : `点击了第${ ev . index } 行` ,
235241 } ) ;
236242 } ,
237243 onScrollToLower ( ) {
238- const { items5 } = this . data ;
239- const newItems = items5 . concat ( newitems ) ;
240244 this . setData ( {
241- items5 : newItems ,
245+ loadMore : 'load' ,
242246 } ) ;
247+ const { items5 } = this . data ;
248+ // 加入 maxList 用于判断“假设”数据加载完毕后的情况
249+ if ( this . data . maxList > 0 ) {
250+ const newItems = items5 . concat ( newitems ) ;
251+ const MAXList = this . data . maxList - 1 ;
252+ this . setData ( {
253+ items5 : newItems ,
254+ maxList : MAXList ,
255+ } ) ;
256+ } else {
257+ // 数据加载完毕之后,改变 loadMore 为 over 即可
258+ this . setData ( {
259+ loadMore : 'over' ,
260+ } ) ;
261+ }
243262 } ,
244263} ) ;
You can’t perform that action at this time.
0 commit comments