当前位置:   article > 正文

支付宝小程序体验—— 业务组件_支付宝小程序下拉框组件

支付宝小程序下拉框组件

开放了好几次的支付宝小程序,终于在昨天818开启了公测,今天一早起来下载ide,看了下文档以及demo,再与微信小程序的开发文档比较一下,发现好像就是copy的啊,然后在知乎上就看到给微信小程序工程师的致歉信,瞬间秒懂了。api接口也就是将wx改成了my,wcss、wxml改成了acss、axml,基础组件基本一样,基本上学了一个另一个也就明了,不过支付宝小程序多了几个业务组件,这几个封装的就比较实用,大概如下:

一:折叠面板。

效果图:

axml:跟官网不同的是又增加了content的列表循环,基本上一看就知道了。

  1. <view class="a-collapse">
  2. <view a:for={{panels}}>
  3. <view
  4. class="a-collapse-title"
  5. onTap="{{onTitleTap}}"
  6. data-index={{index}}
  7. >
  8. {{item.title}}
  9. <view class="{{item.expanded ? 'a-collapse-title-arrow a-collapse-title-arrow-up' : 'a-collapse-title-arrow'}}" />
  10. </view>
  11. <view class="a-collapse-content" a:if={{item.expanded}}>
  12. <view class="a-collapse-content" a:for={{item.content}}>
  13. {{item}}
  14. </view>
  15. </view>
  16. </view>
  17. </view>
acts:

  1. .a-collapse {
  2. border-top: 1px solid #ddd;
  3. background-color: #fff;
  4. color: #000;
  5. }
  6. .a-collapse-title,
  7. .a-collapse-content {
  8. border-bottom: 1px solid #ddd;
  9. }
  10. .a-collapse-title {
  11. position: relative;
  12. height: 88rpx;
  13. line-height: 88rpx;
  14. padding: 0 60rpx 0 30rpx;
  15. font-size: 34rpx;
  16. }
  17. .a-collapse-title-arrow {
  18. position: absolute;
  19. top: 30rpx;
  20. right: 30rpx;
  21. width: 30rpx;
  22. height: 30rpx;
  23. background-image: url("data:image/svg+xml;charset=utf-8,<svg width='16' height='26' viewBox='0 0 16 26' xmlns='http://www.w3.org/2000/svg'><path d='M2 0L0 2l11.5 11L0 24l2 2 14-13z' fill='%23C7C7CC' fill-rule='evenodd'/></svg>");
  24. background-size: contain;
  25. background-repeat: no-repeat;
  26. background-position: 50% 50%;
  27. transform: rotate(90deg);
  28. }
  29. .a-collapse-title-arrow-up {
  30. transform: rotate(270deg);
  31. }
  32. .a-collapse-content {
  33. padding: 20rpx;
  34. font-size: 30rpx;
  35. }
js:
  1. Page({
  2. data: {
  3. collapseData: {
  4. onTitleTap: 'handleTitleTap',
  5. panels: [{
  6. title: 'Title 1',
  7. content: ['Content 1','Content 2','Content 3','Content 4','Content 5'],
  8. expanded: true,
  9. }, {
  10. title: 'Title 2',
  11. content: ['Content 2'],
  12. expanded: false,
  13. },{
  14. title: 'Title 3',
  15. content: ['Content 3'],
  16. expanded: false,
  17. }, {
  18. title: 'Title 4',
  19. content: ['Content 4'],
  20. expanded: false,
  21. },{
  22. title: 'Title 5',
  23. content: ['Content 5'],
  24. expanded: false,
  25. }, {
  26. title: 'Title 6',
  27. content: ['Content 6'],
  28. expanded: false,
  29. },{
  30. title: 'Title 7',
  31. content: ['Content 7'],
  32. expanded: false,
  33. }, {
  34. title: 'Title 8',
  35. content: ['Content 8'],
  36. expanded: false,
  37. }],
  38. },
  39. },
  40. handleTitleTap(e) {
  41. const { index } = e.target.dataset;
  42. const panels = this.data.collapseData.panels;
  43. // android does not supprt Array findIndex
  44. panels[index].expanded = !panels[index].expanded;
  45. this.setData({
  46. collapseData: {
  47. ...this.data.collapseData,
  48. panels: [...panels],
  49. },
  50. });
  51. },
  52. });
二:下拉菜单:

效果图:

axml:

  1. <template name="DropdownSelect">
  2. <view a:if="{{listData}}" class="a-dropdown-wrapper {{active ? 'expand' : ''}}">
  3. <view id="a-dropdown-nav" class="a-dropdown-nav">
  4. <block a:for={{listData}}>
  5. <view
  6. class="a-dropdown-nav-item {{ active && selectedNav ===index ? 'active' : ''}}"
  7. hover-class="a-dropdown-nav-item-hover"
  8. onTap="_onNavItemTap"
  9. data-index={{index}}
  10. >
  11. <text>{{item.nav}}</text>
  12. <view class="triangle"></view>
  13. </view>
  14. </block>
  15. </view>
  16. <scroll-view scroll-y="{{true}}" class="a-dropdown-contents">
  17. <block a:for={{listData}} a:for-item="list" a:for-index="parentIndex">
  18. <view hidden="{{selectedNav !== parentIndex}}">
  19. <view class="a-dropdown-list-items {{active? 'show' : ''}}">
  20. <block a:for={{list.data}} >
  21. <view
  22. class="a-dropdown-list-item {{index !== (list.data.length - 1) ? '': 'last'}}
  23. {{index === list.selectedItem ? 'selected': ''}}"
  24. hover-class="a-dropdown-list-item-hover"
  25. onTap="{{list.onListItemTap || '_onListItemTap'}}"
  26. catchTap="{{list.onListItemTap || '_catchListItemTap'}}"
  27. data-index={{index}}
  28. data-parentIndex={{parentIndex}}
  29. data-title={{item.title}}>
  30. <view class="a-dropdown-list-item-line
  31. {{item.textMode ? 'a-dropdown-list-item-line-' + item.textMode : ''}}">
  32. <image a:if={{item.thumb}} class="a-dropdown-list-item-thumb"
  33. src="{{item.thumb}}" mode="scaleToFill" />
  34. <text class="a-dropdown-list-item-content">{{item.title}}</text>
  35. <view a:if={{item.extra}} class="a-dropdown-list-item-extra" >{{item.extra}}</view>
  36. <view class="a-dropdown-list-item-check"/>
  37. <view class="a-dropdown-list-item-bottom" />
  38. </view>
  39. </view>
  40. </block>
  41. </view>
  42. </view>
  43. </block>
  44. </scroll-view>
  45. <view class="a-dropdown-placeholder"></view>
  46. <view class="a-dropdown-bg" onTap="_catchBgTap"></view>
  47. </view>
  48. </template>
acss:这里的background-image用的都是 阿里巴巴的矢量图标库里的图标然后转化为svg的格式加载的。

  1. .a-dropdown-wrapper {
  2. position: relative;
  3. display: flex;
  4. flex-direction: column;
  5. width: 100%;
  6. height: 100rpx;
  7. }
  8. .a-dropdown-wrapper.expand {
  9. position: fixed;
  10. height: 100%;
  11. z-index: 99;
  12. }
  13. .a-dropdown-nav {
  14. display: flex;
  15. position: relative;
  16. border-bottom: 1px solid #ddd;
  17. background: #fff;
  18. min-height: 100rpx;
  19. z-index: 99;
  20. }
  21. .a-dropdown-nav-item {
  22. flex: 1;
  23. text-align: center;
  24. height: 100rpx;
  25. line-height: 100rpx;
  26. }
  27. .a-dropdown-nav-item-hover {
  28. background: rgba(0, 0, 0, 0.03);
  29. }
  30. .a-dropdown-nav-item.active {
  31. color: #f76a24;
  32. }
  33. .triangle {
  34. width: 0;
  35. height: 0;
  36. border-left: 10rpx solid transparent;
  37. border-right: 10rpx solid transparent;
  38. border-top: 10rpx solid #000;
  39. border-bottom: 0;
  40. vertical-align: middle;
  41. display: inline-block;
  42. }
  43. .a-dropdown-nav-item.active .triangle {
  44. border-bottom: 10rpx solid #f76a24;
  45. border-top: 0;
  46. }
  47. .a-dropdown-contents {
  48. max-height: 100%;
  49. z-index: 2;
  50. }
  51. .a-dropdown-list-items {
  52. height: 0;
  53. overflow: hidden;
  54. background: #fff;
  55. position: relative;
  56. z-index: 98;
  57. }
  58. .a-dropdown-list-items.show {
  59. height: auto;
  60. }
  61. .a-dropdown-list-items .a-dropdown-list-item {
  62. display: flex;
  63. font-size: 30rpx;
  64. line-height: 1.5;
  65. color: #333333;
  66. min-height: 88rpx;
  67. align-items: center;
  68. padding-left: 30rpx;
  69. background: #fff;
  70. }
  71. .a-dropdown-list-item.selected {
  72. color: #f76a24;
  73. }
  74. .a-dropdown-list-item .a-dropdown-list-item-bottom {
  75. display: block;
  76. position: absolute;
  77. width: 100%;
  78. border-bottom: 1px solid #ddd;
  79. left: 0;
  80. bottom: 0;
  81. right: auto;
  82. top: auto;
  83. }
  84. .a-dropdown-list-item .a-dropdown-list-item-thumb {
  85. width: 44rpx;
  86. height: 44rpx;
  87. margin-right: 30rpx;
  88. }
  89. .a-dropdown-list-item .a-dropdown-list-item-line {
  90. position: relative;
  91. display: flex;
  92. flex: 1;
  93. align-items: center;
  94. align-self: stretch;
  95. padding-right: 30rpx;
  96. min-height: 88rpx;
  97. overflow: hidden;
  98. }
  99. .a-dropdown-list-item .a-dropdown-list-item-content {
  100. flex: 1;
  101. font-size: .34rem;
  102. text-align: left;
  103. line-height: 1.5;
  104. width: auto;
  105. overflow: hidden;
  106. text-overflow: ellipsis;
  107. white-space: nowrap;
  108. padding-top: .14rem;
  109. padding-bottom: .14rem;
  110. }
  111. .a-dropdown-list-item.last .a-dropdown-list-item-bottom {
  112. border-bottom: none;
  113. }
  114. .a-dropdown-list-item .a-dropdown-list-item-line-wrap .a-dropdown-list-item-content {
  115. white-space: normal;
  116. }
  117. .a-dropdown-list-item.a-dropdown-list-item-hover {
  118. background-color: #ddd;
  119. }
  120. .a-dropdown-list-item-check {
  121. display: block;
  122. width: 35rpx;
  123. height: 35rpx;
  124. margin-left: 16rpx;
  125. background-image: url('data:image/svg+xml;charset=utf-8,<svg t="1500636672907" class="icon" style="" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1435" xmlns:xlink="http://www.w3.org/1999/xlink" width="350" height="350"><defs><style type="text/css"></style></defs><path d="M824.66816 299.58144 429.54752 694.70208l-190.32064-190.32064c-8.00768-8.00768-20.95104-8.00768-28.95872 0s-8.00768 20.95104 0 28.95872l204.8 204.8c3.9936 3.9936 9.23648 6.00064 14.47936 6.00064s10.48576-2.00704 14.47936-6.00064l409.6-409.6c8.00768-8.00768 8.00768-20.95104 0-28.95872S832.65536 291.57376 824.66816 299.58144z" p-id="1436" fill="#f76a24"></path></svg>');
  126. background-size: contain;
  127. background-repeat: no-repeat;
  128. background-position: 50% 50%;
  129. transition: transform 0.3s;
  130. visibility: hidden;
  131. }
  132. .a-dropdown-list-item.selected .a-dropdown-list-item-check {
  133. visibility: visible;
  134. }
  135. .a-dropdown-placeholder {
  136. min-height: 150rpx;
  137. z-index: 1;
  138. flex: 1;
  139. }
  140. .a-dropdown-bg {
  141. opacity: 0;
  142. transition: opacity linear 0.1s;
  143. }
  144. .expand .a-dropdown-bg {
  145. position: fixed;
  146. top: 0;
  147. left: 0;
  148. width: 100%;
  149. height: 100%;
  150. background: rgb(0, 0, 0);
  151. opacity: 0.4;
  152. z-index: 1;
  153. }

三:通用的错误页:这没什么好说的,看图就知道了。

效果图:

四:宫格

效果图:


axml:

  1. <view class="grid">
  2. <block a:for="{{list}}">
  3. <view
  4. style="width:{{100/(columnNum || 4)}}%;padding-top:{{100/(columnNum || 4)}}%;"
  5. class="grid-item" onTap="handleItemTap"
  6. data-index={{index}}>
  7. <view class="grid-item-wrapper">
  8. <image src="{{item.icon}}" class="grid-icon" mode="aspectFit" />
  9. <text class="grid-text">{{item.text}}</text>
  10. </view>
  11. </view>
  12. </block>
  13. </view>
acss:

  1. .grid {
  2. display: flex;
  3. flex-direction: row;
  4. flex-wrap: wrap;
  5. }
  6. .grid-item {
  7. text-align: center;
  8. position: relative;
  9. background-color: white;
  10. position: relative;
  11. }
  12. .grid-item-wrapper {
  13. position: absolute;
  14. left: 0;
  15. top: 0;
  16. width: 100%;
  17. height: 100%;
  18. display: flex;
  19. justify-content: center;
  20. align-items: center;
  21. flex-direction: column;
  22. }
  23. .grid-icon {
  24. width: 30%;
  25. height: 30%;
  26. }
  27. .grid-text {
  28. color: #000;
  29. font-size: 28rpx;
  30. line-height: 1;
  31. margin-top: 28rpx;
  32. }
j s:
  1. Page({
  2. data: {
  3. grid: {
  4. list: [
  5. {
  6. "icon": "https://zos.alipayobjects.com/rmsportal/HMVRwQoJUDyxZVkTyIqF.png",
  7. "text": "1"
  8. },
  9. {
  10. "icon": "https://zos.alipayobjects.com/rmsportal/HMVRwQoJUDyxZVkTyIqF.png",
  11. "text": "2"
  12. },
  13. {
  14. "icon": "https://zos.alipayobjects.com/rmsportal/HMVRwQoJUDyxZVkTyIqF.png",
  15. "text": "3"
  16. },
  17. {
  18. "icon": "https://zos.alipayobjects.com/rmsportal/HMVRwQoJUDyxZVkTyIqF.png",
  19. "text": "4"
  20. },
  21. {
  22. "icon": "https://zos.alipayobjects.com/rmsportal/HMVRwQoJUDyxZVkTyIqF.png",
  23. "text": "5"
  24. },
  25. {
  26. "icon": "https://zos.alipayobjects.com/rmsportal/HMVRwQoJUDyxZVkTyIqF.png",
  27. "text": "6"
  28. },
  29. {
  30. "icon": "https://zos.alipayobjects.com/rmsportal/HMVRwQoJUDyxZVkTyIqF.png",
  31. "text": "7"
  32. },
  33. {
  34. "icon": "https://zos.alipayobjects.com/rmsportal/HMVRwQoJUDyxZVkTyIqF.png",
  35. "text": "8"
  36. },
  37. {
  38. "icon": "https://zos.alipayobjects.com/rmsportal/HMVRwQoJUDyxZVkTyIqF.png",
  39. "text": "9"
  40. },
  41. {
  42. "icon": "https://zos.alipayobjects.com/rmsportal/HMVRwQoJUDyxZVkTyIqF.png",
  43. "text": "10"
  44. },
  45. {
  46. "icon": "https://zos.alipayobjects.com/rmsportal/HMVRwQoJUDyxZVkTyIqF.png",
  47. "text": "11"
  48. },
  49. {
  50. "icon": "https://zos.alipayobjects.com/rmsportal/HMVRwQoJUDyxZVkTyIqF.png",
  51. "text": "12"
  52. }
  53. ],
  54. columnNum: 4
  55. }
  56. },
  57. handleItemTap(e) {
  58. my.showToast({
  59. content: `第${e.currentTarget.dataset.index}个Item`,
  60. success: (res) => {
  61. },
  62. });
  63. }
  64. })
五:列表:基本上个人中心啊设置啊这些界面就用这个就够了。

效果图:


axml:
  1. <scroll-view scroll-y>
  2. <view>
  3. <view class="a-list">
  4. <block a:if={{header}}>
  5. <view class="a-list-header">{{header}}</view>
  6. </block>
  7. <view a:if={{data}} class="a-list-items">
  8. <block a:for={{data}}>
  9. <view
  10. class="a-list-item {{index !== (data.length - 1) ? '': 'last'}}
  11. am-list-item-{{item.align || 'middle'}}"
  12. hover-class="a-list-item-hover"
  13. onTap="{{onItemTap}}"
  14. data-index={{index}}
  15. >
  16. <view class="a-list-item-line {{item.textMode ? 'a-list-item-line-' + item.textMode : ''}}">
  17. <image a:if={{item.thumb}} class="a-list-item-thumb" src="{{item.thumb}}" mode="scaleToFill" />
  18. <text class="a-list-item-content">{{item.title}}</text>
  19. <view a:if={{item.extra}} class="a-list-item-extra" >{{item.extra}}</view>
  20. <view a:if={{item.arrow}} class="a-list-arrow a-list-arrow-{{item.arrow}}" />
  21. <view class="a-list-item-bottom" />
  22. </view>
  23. </view>
  24. </block>
  25. </view>
  26. </view>
  27. </view>
  28. </scroll-view>
acss:
  1. .a-list {
  2. box-sizing: border-box;
  3. }
  4. .a-list .a-list-header {
  5. padding: 30rpx 30rpx 18rpx;
  6. font-size: 28rpx;
  7. color: #888;
  8. display: inline-block;
  9. width: 100%;
  10. box-sizing: border-box;
  11. }
  12. .a-list .a-list-items .a-list-item {
  13. display: flex;
  14. font-size: 30rpx;
  15. line-height: 1.5;
  16. color: #333333;
  17. min-height: 88rpx;
  18. align-items: center;
  19. padding-left: 30rpx;
  20. background: #fff;
  21. }
  22. .a-list .a-list-item .a-list-item-bottom {
  23. display: block;
  24. position: absolute;
  25. width: 100%;
  26. border-bottom: 1px solid #ddd;
  27. left: 0;
  28. bottom: 0;
  29. right: auto;
  30. top: auto;
  31. }
  32. .a-list .a-list-item .a-list-item-thumb {
  33. width: 44rpx;
  34. height: 44rpx;
  35. margin-right: 30rpx;
  36. }
  37. .a-list .a-list-item .a-list-item-line {
  38. position: relative;
  39. display: flex;
  40. flex: 1;
  41. align-items: center;
  42. align-self: stretch;
  43. padding-right: 30rpx;
  44. min-height: 88rpx;
  45. overflow: hidden;
  46. }
  47. .a-list .a-list-item.am-list-item-top .a-list-item-line {
  48. align-items: flex-start;
  49. }
  50. .a-list .a-list-item.am-list-item-middle .a-list-item-line {
  51. align-items: center;
  52. }
  53. .a-list .a-list-item.am-list-item-bottom .a-list-item-line {
  54. align-items: flex-end;
  55. }
  56. .a-list .a-list-item .a-list-item-content {
  57. flex: 1;
  58. flex: 1;
  59. color: #000;
  60. font-size: .34rem;
  61. text-align: left;
  62. line-height: 1.5;
  63. width: auto;
  64. overflow: hidden;
  65. text-overflow: ellipsis;
  66. white-space: nowrap;
  67. padding-top: .14rem;
  68. padding-bottom: .14rem;
  69. }
  70. .a-list .a-list-item.last .a-list-item-bottom{
  71. border-bottom: none;
  72. }
  73. .a-list .a-list-item .a-list-item-extra {
  74. flex-basis: 36%;
  75. color: #888;
  76. font-size: 32rpx;
  77. text-align: right;
  78. line-height: 1.5;
  79. width: auto;
  80. overflow: hidden;
  81. text-overflow: ellipsis;
  82. white-space: nowrap;
  83. padding-top: .14rem;
  84. padding-bottom: .14rem;
  85. }
  86. .a-list .a-list-item .a-list-item-line-wrap .a-list-item-content, .a-list .a-list-item .a-list-item-line-wrap .a-list-item-extra {
  87. white-space: normal;
  88. }
  89. .a-list .a-list-item.a-list-item-hover {
  90. background-color: #ddd;
  91. }
  92. .a-list .a-list-arrow {
  93. display: block;
  94. width: 30rpx;
  95. height: 30rpx;
  96. margin-left: 16rpx;
  97. background-image: url('data:image/svg+xml;charset=utf-8,<svg width="16" height="26" viewBox="0 0 16 26" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="UI-KIT_基础元件" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="9.9基础元件" transform="translate(-5809.000000, -8482.000000)" fill="#C7C7CC"><polygon id="Disclosure-Indicator" points="5811 8482 5809 8484 5820.5 8495 5809 8506 5811 8508 5825 8495"></polygon></g></g></svg>');
  98. background-size: contain;
  99. background-repeat: no-repeat;
  100. background-position: 50% 50%;
  101. visibility: hidden;
  102. transition: transform 0.3s;
  103. }
  104. .a-list .a-list-arrow.a-list-arrow-horizontal {
  105. visibility: visible;
  106. }
  107. .a-list .a-list-arrow.a-list-arrow-vertical {
  108. visibility: visible;
  109. transform: rotate(90deg);
  110. }
  111. .a-list .a-list-arrow.a-list-arrow-vertical-up {
  112. visibility: visible;
  113. transform: rotate(270deg);
  114. }

js:
  1. Page({
  2. ...list,
  3. data: {
  4. listData: {
  5. onItemTap: 'handleListItemTap',
  6. header: 'list1',
  7. data: [
  8. {
  9. title: '标题文字',
  10. extra: '基本使用'
  11. },
  12. {
  13. thumb: 'https://zos.alipayobjects.com/rmsportal/NTuILTPhmSpJdydEVwoO.png',
  14. title: '标题图片',
  15. arrow: 'horizontal',
  16. },
  17. {
  18. title: '标题文字',
  19. arrow: 'horizontal',
  20. extra: '带箭头'
  21. },
  22. {
  23. thumb: 'https://zos.alipayobjects.com/rmsportal/NTuILTPhmSpJdydEVwoO.png',
  24. title: '标题文字',
  25. arrow: 'horizontal',
  26. extra: '完整使用'
  27. },
  28. {
  29. title: '标题文字不换行很长很长很长很长很长很长很长很长很长很长',
  30. arrow: 'horizontal',
  31. },
  32. {
  33. title: '标题文字换行很长很长很长很长很长很长很长很长很长很长',
  34. arrow: 'horizontal',
  35. textMode: 'wrap'
  36. },
  37. {
  38. title: '标题文字很长很长很长很长很长很长很长很长很长很长很长很长很长很长',
  39. extra: '没有箭头',
  40. textMode: 'wrap'
  41. },
  42. {
  43. title: '标题文字很长很长很长很长很长很长很长很长很长很长很长很长很长很长',
  44. extra: '子元素垂直对齐',
  45. textMode: 'wrap',
  46. align: 'top'
  47. },
  48. ]
  49. },
  50. },
  51. handleListItemTap(e) {
  52. my.showToast({
  53. content: `第${e.currentTarget.dataset.index}个Item`,
  54. success: (res) => {
  55. },
  56. });
  57. }
  58. })
六:标签:demo里只有3个标签,如果加多了的话,就不适用了,这里只需要将外层的display:flex,改成 flex
效果图:


axml:
  1. <view class="container">
  2. <view class="mt-24"><text>事故类别:</text></view>
  3. <view class="tag-list">
  4. <block a:for="{{tags}}">
  5. <view class="a-tag {{props.selected ? 'a-tag-active' : 'a-tag-normal'}}" onTap="{{props.onChange}}" data-selected="{{props.selected}}">
  6. <text class="tag">{{props.label}}<text>
  7. </view>
  8. </block>
  9. </view>
  10. <view class="mt-24">
  11. <text>您选择的是: {{selectedLables}}</text>
  12. </view>
  13. </view>

acss:
  1. .a-tag {
  2. display: inline-block;
  3. position: relative;
  4. font-size: 28rpx;
  5. text-align: center;
  6. padding: 0 30rpx;
  7. height: 50rpx;
  8. line-height: 50rpx;
  9. border-radius: 6rpx;
  10. box-sizing: border-box;
  11. margin: 20rpx;
  12. }
  13. .a-tag-normal {
  14. background-color: #fff;
  15. color: #888;
  16. border: 1px solid #ddd;
  17. }
  18. .a-tag-active {
  19. background-color: #fff;
  20. color: #108ee9;
  21. border: 1px solid #108ee9;
  22. }
  1. .container {
  2. padding: 0 20rpx;
  3. }
  4. .mt-24 {
  5. margin-top: 24rpx;
  6. }
  7. .tag-list {
  8. //display: flex; 将这里去掉就好了
  9. //justify-content: space-between;
  10. flex-wrap: wrap;
  11. margin-top: 24rpx;
  12. }


j s:


  1. Page({
  2. data: {
  3. selectedLables: ',疾病医疗,',
  4. tags: [
  5. {
  6. label: '意外医疗',
  7. selected: false,
  8. onChange: 'onTagChange1',
  9. },
  10. {
  11. label: '疾病医疗',
  12. selected: true,
  13. onChange: 'onTagChange2',
  14. },
  15. {
  16. label: '疾病住院',
  17. selected: false,
  18. onChange: 'onTagChange3',
  19. },
  20. {
  21. label: '疾病住院',
  22. selected: false,
  23. onChange: 'onTagChange4',
  24. },
  25. {
  26. label: '疾病住院',
  27. selected: false,
  28. onChange: 'onTagChange5',
  29. },
  30. {
  31. label: '疾病住院',
  32. selected: false,
  33. onChange: 'onTagChange6',
  34. },
  35. {
  36. label: '疾病住院',
  37. selected: false,
  38. onChange: 'onTagChange7',
  39. }, {
  40. label: '疾病住院',
  41. selected: false,
  42. onChange: 'onTagChange8',
  43. },
  44. ]
  45. },
  46. onTagChange1(e) {
  47. this.onTagChange(e.target.dataset.selected, 0);
  48. },
  49. onTagChange2(e) {
  50. this.onTagChange(e.target.dataset.selected, 1);
  51. },
  52. onTagChange3(e) {
  53. this.onTagChange(e.target.dataset.selected, 2);
  54. },
  55. onTagChange4(e) {
  56. this.onTagChange(e.target.dataset.selected, 3);
  57. },
  58. onTagChange5(e) {
  59. this.onTagChange(e.target.dataset.selected, 4);
  60. },
  61. onTagChange6(e) {
  62. this.onTagChange(e.target.dataset.selected, 5);
  63. },
  64. onTagChange7(e) {
  65. this.onTagChange(e.target.dataset.selected, 6);
  66. },
  67. onTagChange8(e) {
  68. this.onTagChange(e.target.dataset.selected, 7);
  69. },
  70. onTagChange(selected, index) {
  71. const tempTag = [].concat(this.data.tags);
  72. tempTag[index].selected = !selected;
  73. const labels = tempTag.map((item) => item.selected ? item.label : '').join(',');
  74. this.setData({
  75. tags: tempTag,
  76. selectedLables: labels,
  77. });
  78. }
  79. })
以上几个都是常用到的模板,具体模板在 这里,下载就可以了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/88131
推荐阅读
相关标签
  

闽ICP备14008679号