c-picker


底部弹起的滚动选择器

属性

属性名类型必填默认值说明
showBooleanfalse是否点击打开滚动选择器
titleString"请选择"滚动选择器的标题
header-heightNumber100滚动选择器标题栏的高度
data-heightNumber400滚动选择器数据栏的高度
listArray滚动选择器滚动的数据,注意:,在新版内置组件,data 属性名已废弃
default-indexNumber0滚动选择器默认的数据索引
text-alignString"center"滚动选择器的文本样式:"居中"
item-styleString自定义每一项item的样式,如 "color:blue;text-align:center;"
cancel-btn-styleString自定义取消按钮的样式,如 "color:red;text-align:center;"
confirm-btn-styleString自定义确定按钮的样式,如 "color:red;text-align:center;"
c-bind:cancelEventHandle用户点击"取消"时触发:返回事件对象:event.type="cancel"
c-bind:confirmEventHandle用户点击"确定"时触发:返回事件对象:event.type="confirm"
c-bind:selectchangeEventHandle 选择器滚动时触发: 返回事件对象: event.type="selectchange" event.detail = {index}

示例

  1. <template>
  2. <page title="c-picker演示">
  3. <view>
  4. <text class="select-text" c-bind:tap="showClick">点击选择:{{provins[provinsIndex]}}</text>
  5. <c-picker
  6. show="{{pickerShow}}"
  7. height="{{500}}"
  8. header-height="{{100}}"
  9. text-align="center"
  10. data-scroller-height="{{400}}"
  11. list="{{provins}}"
  12. default-index="{{defaultIndex}}"
  13. confirm-btn-style="color:red"
  14. cancel-btn-style="color:red"
  15. c-bind:cancel="cancel"
  16. c-bind:confirm="confirm"
  17. c-bind:selectchange="selectchange">
  18. </c-picker>
  19. </view>
  20. </page>
  21. </template>
  22. <script>
  23. class CPicker {
  24. data = {
  25. provins: [
  26. "北京市",
  27. "天津市",
  28. "河北省",
  29. "山西省",
  30. "内蒙古",
  31. "辽宁省",
  32. "吉林省",
  33. "黑龙江省",
  34. "上海市",
  35. "江苏省",
  36. "浙江省",
  37. "安徽省",
  38. "福建省",
  39. "江西省",
  40. "山东省",
  41. "河南省",
  42. "湖北省",
  43. "湖南省",
  44. "广东省",
  45. "广西",
  46. "海南省",
  47. "重庆市",
  48. "四川省",
  49. "贵州省",
  50. "云南省",
  51. "西藏",
  52. "陕西省",
  53. "甘肃省",
  54. "青海",
  55. "宁夏",
  56. "新疆"
  57. ],
  58. defaultIndex: 0,
  59. provinsIndex: 0,
  60. pickerShow: false
  61. }
  62. computed = {}
  63. watch = {}
  64. methods = {
  65. selectchange(e) {
  66. this.provinsIndex = this.defaultIndex = e.detail.index;
  67. },
  68. showClick() {
  69. this.pickerShow = true;
  70. },
  71. cancel() {
  72. this.pickerShow = false;
  73. },
  74. confirm() {
  75. this.pickerShow = false;
  76. }
  77. }
  78. beforeCreate() {}
  79. created() {}
  80. beforeMount() {}
  81. mounted() {}
  82. beforeDestroy() {}
  83. destroyed() {}
  84. }
  85. export default new CPicker();
  86. </script>
  87. <style scoped>
  88. .container {
  89. background: #f8f8f8;
  90. }
  91. .page-demo {
  92. background: #fafafa;
  93. }
  94. .title-text {
  95. color: #999;
  96. margin: 30cpx 20cpx 10cpx;
  97. display: block;
  98. font-size: 28cpx;
  99. }
  100. .picker-item {
  101. background: #fff;
  102. border-top: 1px solid #d9d9d9;
  103. border-bottom: 1px solid #d9d9d9;
  104. display: flex;
  105. flex-direction: row;
  106. }
  107. .picker-text-left {
  108. font-size: 40cpx;
  109. height: 70cpx;
  110. line-height: 70cpx;
  111. margin-left: 20cpx;
  112. width: 300cpx;
  113. }
  114. .picker-text-right {
  115. font-size: 40cpx;
  116. height: 70cpx;
  117. line-height: 70cpx;
  118. margin-left: 20cpx;
  119. flex: 1;
  120. text-align: center;
  121. }
  122. .select-text {
  123. font-size: 32cpx;
  124. text-align: center;
  125. display: flex;
  126. justify-content: center;
  127. align-items: center;
  128. }
  129. </style>
  130. <script cml-type="json">
  131. {
  132. "base": {
  133. "usingComponents": {
  134. "c-picker": "cml-ui/components/c-picker/c-picker"
  135. }
  136. }
  137. }
  138. </script>

c-picker  - 图1wx

c-picker  - 图2web

c-picker  - 图3native