wxc-list

列表组件 - 小程序组件

Install

  1. $ min install @minui/wxc-list

Demos

配置icon

列表 list - 图1

  1. <template>
  2. <view class="list-wrap">
  3. <view class="list-item">
  4. <wxc-list
  5. wx:for="{{list}}"
  6. wx:key="index"
  7. class="item"
  8. title="{{item.title}}"
  9. desc="{{item.slot? '' : item.desc}}"
  10. mode="{{index == list.length-1 ? 'none': ''}}"
  11. src="{{item.src}}">
  12. <view wx:if="{{item.slot && item.desc}}" class="desc-highlight">{{item.desc}}</view>
  13. </wxc-list>
  14. </view>
  15. <view class="list-item">
  16. <wxc-list
  17. class="item"
  18. icon="help"
  19. icon-color="#69A0DD"
  20. title="客服与帮助"></wxc-list>
  21. <wxc-list
  22. class="item"
  23. icon="feedback"
  24. icon-color="#69A0DD"
  25. mode="none"
  26. title="意见反馈"></wxc-list>
  27. </view>
  28. </view>
  29. </template>
  30. <script>
  31. export default {
  32. config: {
  33. usingComponents: {
  34. 'wxc-list': '@minui/wxc-list',
  35. 'wxc-icon': '@minui/wxc-icon'
  36. }
  37. },
  38. data: {
  39. list: [{
  40. title: '打卡领红包',
  41. desc: '您有1个10元红包可领取',
  42. slot: false,
  43. src: 'https://s10.mogucdn.com/mlcdn/c45406/171226_2kall2je2079dh6ddkgc31d27cce2_38x38.png'
  44. }, {
  45. title: '优惠券',
  46. desc: '满100减20',
  47. slot: true,
  48. src: 'https://s10.mogucdn.com/mlcdn/c45406/170603_7ida8bdc21j18b91aa2ii3lk38b9i_38x38.png'
  49. }, {
  50. title: '钱和红包',
  51. desc: '',
  52. slot: false,
  53. src: 'https://s10.mogucdn.com/mlcdn/c45406/171011_0acg74g776ig2459c1c6gkge07hch_40x40.png'
  54. }, {
  55. title: '我的消息',
  56. desc: '和卖家沟通在这里',
  57. slot: false,
  58. src: 'https://s10.mogucdn.com/mlcdn/c45406/170603_0ea73id6h6926k281cdhia0dg5gdg_38x38.png'
  59. }, {
  60. title: '我的收藏',
  61. desc: '',
  62. slot: false,
  63. src: 'https://s10.mogucdn.com/mlcdn/c45406/170603_6h37fg4074i3a2l2gb92dbbc15k84_38x38.png'
  64. }, {
  65. title: '足迹',
  66. desc: '',
  67. slot: false,
  68. src: 'https://s10.mogucdn.com/mlcdn/c45406/170603_00di1ei7f095j8b996icg79kl91kc_38x38.png'
  69. }, {
  70. title: '我的拼团',
  71. desc: '',
  72. slot: false,
  73. src: 'https://s10.mogucdn.com/mlcdn/c45406/170603_55gkg003el4k2jbg2d2ieh030fjcf_38x38.png'
  74. }, {
  75. title: '充值中心',
  76. desc: '',
  77. slot: false,
  78. src: 'https://s10.mogucdn.com/mlcdn/c45406/180109_26hggaiha8k7blig5k4ihk5k967ii_38x38.png'
  79. }]
  80. },
  81. methods: { }
  82. }
  83. </script>
  84. <style>
  85. .list-wrap {
  86. width: 100%;
  87. background: #efefef;
  88. padding-bottom: 30rpx;
  89. padding-top: 30rpx;
  90. }
  91. .list-item {
  92. background: #fff;
  93. margin-bottom: 30rpx;
  94. }
  95. .list-item:last-child {
  96. margin: 0;
  97. }
  98. .item {
  99. flex: 1;
  100. }
  101. .desc-highlight {
  102. font-size: 24rpx;
  103. height: 38rpx;
  104. padding: 0 22rpx;
  105. border: 1px solid #f5342f;
  106. border-radius: 20rpx;
  107. color: #f5342f;
  108. line-height: 38rpx;
  109. }
  110. </style>

基础用法

列表 list - 图2

  1. <template>
  2. <view class="list-wrap">
  3. <view class="list-item">
  4. <wxc-list title="标题文字" desc="内容描述" mode="none"></wxc-list>
  5. <wxc-list title="标题文字" desc="内容描述" dot="{{true}}"></wxc-list>
  6. <wxc-list title="标题文字" desc="内容描述" arrow="{{false}}"></wxc-list>
  7. <wxc-list title="标题文字" arrow="{{false}}" mode="none">
  8. <switch type="switch" color="#ff5777"></switch>
  9. </wxc-list>
  10. </view>
  11. <view class="list-item">
  12. <view class="list-check">
  13. <view class="check-wrap"></view>
  14. <wxc-list class="item" title="标题文字" desc="内容描述"></wxc-list>
  15. </view>
  16. <view class="list-check">
  17. <view class="check-wrap" bindtap="onCheck">
  18. <wxc-icon wx:if="{{check}}" class="check" type="check" size="46" color="#ff5777"></wxc-icon>
  19. </view>
  20. <wxc-list class="item" title="标题文字" desc="内容描述" mode="none"></wxc-list>
  21. </view>
  22. </view>
  23. <view class="list-item">
  24. <view class="list-check">
  25. <image class="list-image radius" mode="aspectFill" src="http://s2.mogucdn.com/new1/v1/bdefaultavatar/04.jpg"></image>
  26. <wxc-list class="item" title="标题文字" detail="内容描述"></wxc-list>
  27. </view>
  28. <view class="list-check">
  29. <image class="list-image" mode="aspectFill" src="http://s3.mogucdn.com/mlcdn/1689c6/180330_8gak8gf7809jhfi8i0l90i79bca3g_400x400.jpg"></image>
  30. <wxc-list class="item" title="标题文字" detail="内容描述" mode="none"></wxc-list>
  31. </view>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. export default {
  37. config: {
  38. usingComponents: {
  39. 'wxc-list': '@minui/wxc-list',
  40. 'wxc-icon': '@minui/wxc-icon'
  41. }
  42. },
  43. data: {
  44. check: true
  45. },
  46. /** note: 在 wxp 文件或者页面文件中请去掉 methods 包装 */
  47. methods: {
  48. onCheck() {
  49. let check = this.data.check;
  50. this.setData({
  51. check: !check
  52. })
  53. }
  54. }
  55. }
  56. </script>
  57. <style>
  58. .list-wrap {
  59. width: 100%;
  60. background: #efefef;
  61. padding-bottom: 30rpx;
  62. padding-top: 30rpx;
  63. }
  64. .list-item {
  65. background: #fff;
  66. margin-bottom: 30rpx;
  67. }
  68. .list-item:last-child {
  69. margin: 0;
  70. }
  71. .list-check {
  72. display: flex;
  73. align-items: center
  74. }
  75. .check-wrap {
  76. position: relative;
  77. width: 40rpx;
  78. height: 40rpx;
  79. margin-left: 30rpx;
  80. border-radius: 100%;
  81. border: 1px solid #d8d8d8;
  82. }
  83. .check {
  84. position: absolute;
  85. top: 0;
  86. left: -2rpx;
  87. width: 100%;
  88. height: 100%;
  89. line-height: 42rpx;
  90. }
  91. .list-image {
  92. width: 102rpx;
  93. height: 102rpx;
  94. margin-left: 30rpx;
  95. }
  96. .radius {
  97. border-radius: 100px;
  98. }
  99. .item {
  100. flex: 1;
  101. }
  102. .list-image {
  103. width: 102rpx;
  104. height: 102rpx;
  105. background: #d8d8d8;
  106. }
  107. </style>

API

List

名称描述
title[说明]:列表项左侧的标题。[类型]:String[默认值]:""
detail[说明]:标题下方的的详细描述。[类型]:String[默认值]:""
desc[说明]:列表项右侧的描述。[类型]:String[默认值]:""
src[说明]:标题前面的图标,自定义图片链接。优先级高于 icon。[类型]:String[默认值]:""
icon[说明]:标题前面的图标,类型见 wxc-icon 组件。[类型]:String[默认值]:""
icon-color[说明]:标题前面的icon图标颜色,同 icon 一同使用。[类型]:String[默认值]:#ff5077
dot[说明]:右侧描述部分前面的提醒红点。[类型]:Boolean[默认值]:false
dot-color[说明]:右侧描述部分前面的提醒红点颜色,与 dot 一同使用。[类型]:String[默认值]:#f5123e
arrow[说明]:是否显示箭头。[类型]:Boolean[默认值]:true
mode[说明]:列表项边框模式。[类型]:String[可选值]:normal,有下边框;none,无边框。[默认值]:normal
bind:click[说明]:点击列表项时触发的事件。组件带 slot 时给组件添加原生事件后点击到 slot 时会报错,故增加自定义事件避免此错误。

ChangeLog

v1.0.0(2018-3-29)

  • 初始版本