list


可滚动长列表。

<list> 标签内可包含多条 <cell>,适合用于长列表的展示。

<cell> 使用文档 cell

属性

属性名类型必填默认值说明
heightNumber必传0定义滚动区域的高度
bottom-offsetNumber0距底部/右边多远时(单位cpx),触发 onBottom 事件
c-bind:scrolltobottomEventHandle滚动到底部,会触发 scrolltobottom 事件 返回事件对象: event.type= "scrolltobottom" event.detail = { direction }
c-bind:onscrollEventHandle滚动时触发, 返回事件对象: event.type = 'scroll' event.detail = {scrollLeft, scrollTop, scrollHeight, scrollWidth, deltaX, deltaY}

限制

  • 不允许相同方向的 <list> 或者 <scroller> 互相嵌套,换句话说就是嵌套的 <list>/<scroller> 必须是不同的方向。
    举个例子,不允许一个垂直方向的 <list> 嵌套的一个垂直方向的 <scroller> 中,但是一个垂直方向的 <list> 是可以嵌套的一个水平方向的 list 或者 <scroller> 中的。

示例

  1. <template>
  2. <view class="container">
  3. <list
  4. bottom-offset="{{bottomOffset}}"
  5. c-bind:scrolltobottom="onBottom"
  6. c-bind:onscroll="onScroll"
  7. height="{{winHeight}}"
  8. >
  9. <cell
  10. class="cell"
  11. c-for="{{lists}}"
  12. c-for-index="i"
  13. c-for-item="item"
  14. data-idx="{{i}}"
  15. >
  16. <view class="panel">
  17. <text class="text">{{item}}</text>
  18. </view>
  19. </cell>
  20. </list>
  21. </view>
  22. </template>
  23. <script>
  24. import cml from 'chameleon-api'
  25. const LOADMORE_COUNT = 4
  26. class List {
  27. data = {
  28. /**
  29. * list 配置 子元素必须是 cell 标签
  30. */
  31. bottomOffset: 20,
  32. lists: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
  33. winHeight: 0
  34. }
  35. mounted(res) {
  36. cml.getSystemInfo().then((info)=>{
  37. this.winHeight = Number(info.viewportHeight)
  38. })
  39. }
  40. methods = {
  41. onBottom(e) {
  42. cml.showToast({
  43. message: "loadmore",
  44. duration: 1000
  45. });
  46. setTimeout(() => {
  47. const length = this.lists.length
  48. for (let i = length; i < length + LOADMORE_COUNT; ++i) {
  49. this.lists.push(i + 1)
  50. }
  51. }, 800)
  52. },
  53. onScroll(e) {
  54. }
  55. }
  56. }
  57. export default new List();
  58. </script>
  59. <style scoped>
  60. .container {
  61. position: absolute;
  62. top: 88cpx;
  63. left: 0;
  64. right: 0;
  65. bottom: 0;
  66. }
  67. .panel {
  68. display: flex;
  69. width: 600cpx;
  70. height: 300cpx;
  71. margin-left: 75cpx;
  72. margin-top: 35cpx;
  73. margin-bottom: 35cpx;
  74. flex-direction: column;
  75. justify-content: center;
  76. border-width: 2cpx;
  77. border-style: solid;
  78. border-color: rgb(162, 217, 192);
  79. background-color: rgba(162, 217, 192, 0.2);
  80. }
  81. .text {
  82. font-size: 88cpx;
  83. text-align: center;
  84. color: #41B883;
  85. }
  86. </style>
  87. <script cml-type="json">
  88. {
  89. "base": {}
  90. }
  91. </script>

list  - 图1wx

list  - 图2web

list  - 图3native

推荐使用

  • 视窗为填满设备屏幕,示例如下
    <list> 为根节点时无需设置高度,但是内嵌 <list> 高度必须可计算,你可以使用 flex 或 postion 将 <list> 设为一个响应式高度(例如全屏显示), 也可以显式设置 <list> 组件的 height 样式。
  1. <view style="position:absolute;top: 0;left: 0;bottom: 0;right: 0;">
  2. <list>
  3. ...
  4. </list>
  5. </view>

Bug & Tip

  • <list>组件的父容器必须为可定位元素, <list>内容的布局由父容器决定。
  • <list> 中不可以使用 <textarea><video> 组件。