Picker 拾取器请使用手机扫码体验

提供多个选项集合供用户选择其中一项。

基本用法

  1. html
    <nut-picker
  2. :is-visible="isVisible1"
  3. :default-value-data="defaultValueData1"
  4. :list-data="listData1"
  5. @close="switchPicker('isVisible1')"
  6. @confirm="setYearValue"
  7. >
  8. </nut-picker>

多列用法

  1. html
    <nut-picker
  2. :is-visible="isVisible0"
  3. :list-data="listData0"
  4. title="请选择年月"
  5. :default-value-data="defaultValueData0"
  6. @close="switchPicker('isVisible0')"
  7. @confirm="setChooseValue0"
  8. >
  9. </nut-picker>

联动(省市区)

  1. html
    <nut-picker
  2. :is-visible="isVisible"
  3. title="请选择城市"
  4. :list-data="listData"
  5. :default-value-data="defaultValueData"
  6. @close="switchPicker('isVisible')"
  7. @confirm="setChooseValue"
  8. @choose="updateChooseValue"
  9. @close-update="closeUpdateChooseValue"
  10. >
  11. </nut-picker>
  1. javascript
    export default {
  2. data() {
  3. return {
  4. date: null,
  5. isVisible0: false,
  6. listData0: [
  7. ['2010', '2011', '2012', '2013', '2014', '2015', '2016','2017', '2018', '2019', '2020', '2021', '2022', '2023' ],
  8. ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12']
  9. ],
  10. defaultValueData0:['2012', '2'],
  11. city: null,
  12. isVisible: false,
  13. data:{
  14. '北京': ['北京'],
  15. '黑龙江': ['哈尔滨','绥化','漠河','大兴安岭','牡丹江','佳木斯','齐齐哈尔','大庆','五大连池'],
  16. '江西': ['九江', '南昌', '赣州'],
  17. '上海': ['上海'],
  18. '重庆': ['重庆'],
  19. '内蒙古': ['呼和浩特', '呼和浩特1','呼和浩特2', '呼和浩特3','呼和浩特4', '呼和浩特5','呼和浩特6', '呼和浩特7']
  20. },
  21. dataSub: {
  22. '上海': ['测试1', '测试2'],
  23. '北京': ['西城区', '东城区', '大兴区', '朝阳区', '海淀区'],
  24. '南昌': ['青山湖区', '西湖区', '宏都中路', '梦时代', '八一广场'],
  25. '绥化': ['明水', '拜泉'],
  26. '哈尔滨': ['道里区', '道外区']
  27. },
  28. listData: [
  29. [ '上海', '黑龙江', '北京', '重庆', '江西','内蒙古' ]
  30. ],
  31. defaultValueData: null,
  32. year: null,
  33. isVisible1: false,
  34. listData1: [['2010', '2011', '2012', '2013', '2014', '2015', '2016','2017', '2018' ]],
  35. defaultValueData1: null
  36. };
  37. },
  38. created() {
  39. this.listData = [...[this.listData[0]], this.data[this.listData[0][0]], this.dataSub[this.data[this.listData[0][0]]] ];
  40. },
  41. methods: {
  42. switchPicker(param) {
  43. this[`${param}`] = !this[`${param}`];
  44. },
  45. setChooseValue0(chooseData) {
  46. this.date = `${chooseData[0]}年${chooseData[1]}月`;
  47. },
  48. setChooseValue(chooseData) {
  49. this.city = `${chooseData[0]}-${chooseData[1]}${chooseData[2] ? '-' + chooseData[2] : ''}`;
  50. },
  51. setYearValue(chooseData) {
  52. this.year = `${chooseData[0]}年`;
  53. },
  54. updateLinkage(self, value, index, chooseValue, cacheValueData) {
  55. if (!value) {
  56. return false;
  57. }
  58. switch(index) {
  59. case 1:
  60. let i = this.listData[0].indexOf(value);
  61. this.listData.splice(index, 1, [...this.data[this.listData[0][i]]]);
  62. chooseValue = chooseValue ? chooseValue : this.listData[index][0];
  63. self && self.updateChooseValue(self, index, chooseValue);
  64. this.updateLinkage(self, chooseValue, 2, (cacheValueData && cacheValueData[2] ? cacheValueData[2] : null));
  65. break;
  66. case 2:
  67. let areaData = this.dataSub[value] ? this.dataSub[value] : [];
  68. this.listData.splice(index, 1, [...areaData]);
  69. chooseValue = chooseValue ? chooseValue : this.listData[index][0];
  70. self && self.updateChooseValue(self, index, chooseValue);
  71. break;
  72. }
  73. },
  74. updateChooseValue(self, index, value, cacheValueData) {
  75. index < 2 && this.updateLinkage(self, value, (index + 1), null);
  76. },
  77. closeUpdateChooseValue(self, chooseData) {
  78. this.updateLinkage(self, chooseData[0], 1, chooseData[1], chooseData);
  79. },
  80. modifyCity() {
  81. this.updateLinkage('', '重庆', 1, '重庆');
  82. this.defaultValueData = ['重庆', '重庆'];
  83. },
  84. modifyYear(){
  85. this.defaultValueData1 = ['2018'];
  86. }
  87. }
  88. };

Prop

字段说明类型默认值
isVisible是否可见Booleanfalse
customClassName自定义classStringnull
title设置标题Stringnull
listData列表数据Array[]
defaultValueData默认选中Array[]

Event

字段说明回调参数
confirm点击确认按钮时候回调返回选中值
choose每一列值变更时调用依次返回this、改变的列数,改变值,当前选中值
chclose-update联动时,关闭时回调依次返回this、当前选中值
close关闭时触发-