index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <demo-section>
  3. <demo-block :title="$t('basicUsage')">
  4. <van-picker
  5. :columns="$t('column1')"
  6. @change="onChange1"
  7. />
  8. </demo-block>
  9. <demo-block :title="$t('defaultIndex')">
  10. <van-picker
  11. :columns="$t('column1')"
  12. :default-index="2"
  13. @change="onChange1"
  14. />
  15. </demo-block>
  16. <demo-block :title="$t('title3')">
  17. <van-picker
  18. show-toolbar
  19. :title="$t('area')"
  20. :columns="$t('column1')"
  21. @cancel="onCancel"
  22. @confirm="onConfirm"
  23. />
  24. </demo-block>
  25. <demo-block :title="$t('title2')">
  26. <van-picker :columns="$t('column2')" />
  27. </demo-block>
  28. <demo-block :title="$t('title4')">
  29. <van-picker
  30. :columns="columns"
  31. @change="onChange2"
  32. />
  33. </demo-block>
  34. <demo-block :title="$t('loadingStatus')">
  35. <van-picker
  36. loading
  37. :columns="columns"
  38. />
  39. </demo-block>
  40. </demo-section>
  41. </template>
  42. <script>
  43. export default {
  44. i18n: {
  45. 'zh-CN': {
  46. area: '标题',
  47. title2: '禁用选项',
  48. title3: '展示顶部栏',
  49. title4: '多列联动',
  50. defaultIndex: '默认选中项',
  51. column1: ['杭州', '宁波', '温州', '嘉兴', '湖州'],
  52. column2: [
  53. { text: '杭州', disabled: true },
  54. { text: '宁波' },
  55. { text: '温州' }
  56. ],
  57. column3: {
  58. 浙江: ['杭州', '宁波', '温州', '嘉兴', '湖州'],
  59. 福建: ['福州', '厦门', '莆田', '三明', '泉州']
  60. },
  61. toastContent: (value, index) => `当前值:${value}, 当前索引:${index}`
  62. },
  63. 'en-US': {
  64. area: 'Title',
  65. title2: 'Disable Option',
  66. title3: 'Show Toolbar',
  67. title4: 'Multi Columns',
  68. defaultIndex: 'Default Index',
  69. column1: ['Delaware', 'Florida', 'Georqia', 'Indiana', 'Maine'],
  70. column2: [
  71. { text: 'Delaware', disabled: true },
  72. { text: 'Florida' },
  73. { text: 'Georqia' }
  74. ],
  75. column3: {
  76. Group1: ['Delaware', 'Florida', 'Georqia', 'Indiana', 'Maine'],
  77. Group2: ['Alabama', 'Kansas', 'Louisiana', 'Texas']
  78. },
  79. toastContent: (value, index) => `Value: ${value}, Index:${index}`
  80. }
  81. },
  82. computed: {
  83. columns() {
  84. const column = this.$t('column3');
  85. return [
  86. {
  87. values: Object.keys(column),
  88. className: 'column1'
  89. },
  90. {
  91. values: column[Object.keys(column)[0]],
  92. className: 'column2',
  93. defaultIndex: 2
  94. }
  95. ];
  96. }
  97. },
  98. methods: {
  99. onChange1(picker, value, index) {
  100. this.$toast(this.$t('toastContent', value, index));
  101. },
  102. onChange2(picker, values) {
  103. picker.setColumnValues(1, this.$t('column3')[values[0]]);
  104. },
  105. onConfirm(value, index) {
  106. this.$toast(this.$t('toastContent', value, index));
  107. },
  108. onCancel() {
  109. this.$toast(this.$t('cancel'));
  110. }
  111. }
  112. };
  113. </script>