选择器 Picker & Select

基本用法

选择器 Picker - 图1

  1. <template lang="html">
  2. <div>
  3. <div class="demo-hidden">
  4. <za-panel>
  5. <za-panel-header title="基本" ></za-panel-header>
  6. <za-panel-body>
  7. <za-cell title="单列">
  8. <za-button slot='description' size='xs' @click='visible1 = true'>开启</za-button>
  9. </za-cell>
  10. <za-cell title="多列">
  11. <za-button slot='description' size='xs' @click='visible2 = true'>开启</za-button>
  12. </za-cell>
  13. <za-cell title="多列联动">
  14. <za-button slot='description' size='xs' @click='visible3 = true'>开启</za-button>
  15. </za-cell>
  16. <za-cell title="自定义格式">
  17. <za-button slot='description' size='xs' @click='visible4 = true'>开启</za-button>
  18. </za-cell>
  19. </za-panel-body>
  20. </za-panel>
  21. <za-picker :close-on-click-modal='false' :visible.sync='visible1' :data-source='data1' @ok='handleOk1' ></za-picker>
  22. <za-picker :visible.sync='visible2' :data-source='data2' @ok='handleOk' ></za-picker>
  23. <za-picker :visible.sync='visible3' :data-source='data3' @ok='handleOk' ></za-picker>
  24. <za-picker :visible.sync='visible4' :data-source='data4' @ok='handleOk2' placeholder='自定义placeholder'
  25. value-member="code" :item-render='(item) => item.name' ></za-picker>
  26. <za-panel>
  27. <za-panel-header title="城市选择器 Select"></za-panel-header>
  28. <za-panel-body>
  29. <za-cell title="省市选择">
  30. <za-select
  31. v-model='v6'
  32. :data-source='District'
  33. @ok='handleOk'
  34. @change='handleChange'
  35. @cancel='handleCancel'
  36. :cols='2'></za-select>
  37. </za-cell>
  38. <za-cell title="省市区选择">
  39. <za-select
  40. :data-source='District'
  41. v-model='v7'
  42. :display-render="selected => selected.map(item => item.label).join('/')"
  43. @ok='handleOk'
  44. @change='handleChange'
  45. @cancel='handleCancel'></za-select>
  46. </za-cell>
  47. </za-panel-body>
  48. </za-panel>
  49. <za-panel>
  50. <za-panel-header title="层叠式选择器 StackPicker"></za-panel-header>
  51. <za-panel-body>
  52. <za-cell title="级联选择">
  53. <za-stack-picker
  54. v-model='v10'
  55. title="级联选择"
  56. placeholder="请选择"
  57. :data-source='District'
  58. :display-render="selected => selected.map(item => item.label).join('-')"
  59. @ok='handleOk'
  60. @change='handleChange'
  61. @cancel='handleCancel'></za-stack-picker>
  62. </za-cell>
  63. </za-panel-body>
  64. </za-panel>
  65. <za-panel>
  66. <za-panel-header title="平铺选择器 PickerView" ></za-panel-header>
  67. <za-panel-body>
  68. <za-picker-view :default-value="v5" :data-source='data5' @change='handleChange' ></za-picker-view>
  69. </za-panel-body>
  70. </za-panel>
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. const District = [{
  76. "value": "340000",
  77. "label": "安徽省",
  78. "children": [{
  79. "value": "340800",
  80. "label": "安庆市",
  81. "children": [{
  82. "value": "340803",
  83. "label": "大观区",
  84. "children": []
  85. }, {
  86. "value": "340822",
  87. "label": "怀宁县",
  88. "children": []
  89. }, {
  90. "value": "340882",
  91. "label": "其它区",
  92. "children": []
  93. }]
  94. }]
  95. },{
  96. "value": "310000",
  97. "label": "上海",
  98. "children": [{
  99. "value": "310100",
  100. "label": "上海市",
  101. "children": [{
  102. "value": "310113",
  103. "label": "宝山区",
  104. "children": []
  105. }, {
  106. "value": "310105",
  107. "label": "长宁区",
  108. "children": []
  109. }, {
  110. "value": "310230",
  111. "label": "崇明县",
  112. "children": []
  113. }, {
  114. "value": "310152",
  115. "label": "川沙区",
  116. "children": []
  117. }]
  118. }]
  119. }];
  120. export default {
  121. data() {
  122. return {
  123. visible1: false,
  124. visible2: false,
  125. visible3: false,
  126. visible4: false,
  127. visible6: false,
  128. visible7: false,
  129. v1: '2',
  130. v2: ['2','3'],
  131. v3: ['2','21'],
  132. v4: '',
  133. v5: ['2','22'],
  134. v6: '',
  135. v7: '',
  136. v10: [],
  137. District,
  138. data1: [
  139. { value: '1', label: '选项一' },
  140. { value: '2', label: '选项二' },
  141. ],
  142. data2: [
  143. [
  144. { value: '1', label: '选项一' },
  145. { value: '2', label: '选项二' },
  146. ],
  147. [
  148. { value: '3', label: '选项A' },
  149. { value: '4', label: '选项B' },
  150. ],
  151. ],
  152. data3: [
  153. {
  154. value: '1',
  155. label: '北京市',
  156. children: [
  157. { value: '11', label: '海淀区' },
  158. { value: '12', label: '西城区' },
  159. ],
  160. },
  161. {
  162. value: '2',
  163. label: '上海市',
  164. children: [
  165. { value: '21', label: '杨浦区' },
  166. { value: '22', label: '静安区' },
  167. ],
  168. },
  169. ],
  170. data4: [
  171. {
  172. code: '1',
  173. name: '北京市',
  174. children: [
  175. { code: '11', name: '海淀区' },
  176. { code: '12', name: '西城区' },
  177. ],
  178. },
  179. {
  180. code: '2',
  181. name: '上海市',
  182. children: [
  183. { code: '21', name: '黄埔区' },
  184. { code: '22', name: '虹口区' },
  185. ],
  186. },
  187. ],
  188. data5: [
  189. {
  190. value: '1',
  191. label: '北京市',
  192. children: [
  193. { value: '11', label: '海淀区' },
  194. { value: '12', label: '西城区' },
  195. ],
  196. },
  197. {
  198. value: '2',
  199. label: '上海市',
  200. children: [
  201. { value: '21', label: '杨浦区' },
  202. { value: '22', label: '静安区' },
  203. ],
  204. },
  205. ]
  206. }
  207. },
  208. methods: {
  209. handleOk1(v) {
  210. console.log('it may still scrolling when ok is clicked. so ues v-model or @change instead')
  211. console.log(v);
  212. },
  213. handleOk(v) {
  214. console.log('it may still scrolling when ok is clicked. so ues v-model or @change instead')
  215. console.log(v);
  216. },
  217. handleOk2(v) {
  218. console.log('it may still scrolling when ok is clicked. so ues v-model or @change instead')
  219. console.log(v);
  220. },
  221. handleChange(v) {
  222. console.log(v);
  223. },
  224. handleCancel(event) {
  225. console.log('cancelled');
  226. },
  227. displayGenerator(selected) {
  228. return selected.map(item => item.name).join('/')
  229. }
  230. },
  231. };
  232. </script>

API

Picker & Select Attributes

属性类型默认值可选值/参数说明
prefixClsstringza-picker类名前缀
data-sourcearray[ ]数据源
visibleboolfalse是否显示, 支持.sync修饰符 (v2.3.0+)
default-valuearray, string初始值
v-modelarray, string绑定值
valueMemberstring'value'值字段对应的key
displayMemberstring'label'选项列表显示字段对应的key
disabledboolfalse是否禁用
titlestring'请选择'选择器标题
placeholderstring'请选择'输入提示信息
displayRenderfuncnoop所选值渲染
itemRenderfuncnoop滚轮区域选项址值渲染
colsnumber级联选择器的级数

Picker & Select Events

事件名称说明回调参数
ok点击确定时触发的回调函数选中值的对象列表
cancel点击取消时触发的回调函数event对象
change滚动时值变化时触发的回调函数选中值的对象列表