index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <demo-section>
  3. <demo-block :title="$t('basicUsage')">
  4. <van-tree-select
  5. :items="items"
  6. :main-active-index="mainActiveIndex"
  7. :active-id="activeId"
  8. @navclick="onNavClick"
  9. @itemclick="onItemClick"
  10. />
  11. </demo-block>
  12. </demo-section>
  13. </template>
  14. <script>
  15. export default {
  16. i18n: {
  17. 'zh-CN': {
  18. group1: '所有城市',
  19. group2: '浙江',
  20. group3: '江苏',
  21. group4: '福建',
  22. city1: [{
  23. text: '杭州',
  24. id: 1
  25. }, {
  26. text: '温州',
  27. id: 2
  28. }, {
  29. text: '宁波',
  30. id: 3,
  31. disabled: true
  32. }, {
  33. text: '义乌',
  34. id: 4
  35. }],
  36. city2: [{
  37. text: '南京',
  38. id: 5
  39. }, {
  40. text: '无锡',
  41. id: 6
  42. }, {
  43. text: '徐州',
  44. id: 7
  45. }, {
  46. text: '苏州',
  47. id: 8
  48. }],
  49. city3: [{
  50. text: '泉州',
  51. id: 9
  52. }, {
  53. text: '厦门',
  54. id: 10
  55. }]
  56. },
  57. 'en-US': {
  58. group1: 'All',
  59. group2: 'Group1',
  60. group3: 'Group2',
  61. group4: 'Group3',
  62. city1: [{
  63. text: 'Delaware',
  64. id: 1
  65. }, {
  66. text: 'Florida',
  67. id: 2
  68. }, {
  69. text: 'Georqia',
  70. id: 3,
  71. disabled: true
  72. }, {
  73. text: 'Indiana',
  74. id: 4
  75. }],
  76. city2: [{
  77. text: 'Alabama',
  78. id: 5
  79. }, {
  80. text: 'Kansas',
  81. id: 6
  82. }, {
  83. text: 'Louisiana',
  84. id: 7
  85. }, {
  86. text: 'Texas',
  87. id: 8
  88. }],
  89. city3: [{
  90. text: 'Alabama',
  91. id: 9
  92. }, {
  93. text: 'Kansas',
  94. id: 10
  95. }],
  96. }
  97. },
  98. data() {
  99. return {
  100. mainActiveIndex: 0,
  101. activeId: 1
  102. };
  103. },
  104. computed: {
  105. items() {
  106. return [{
  107. text: this.$t('group1'),
  108. children: [...this.$t('city1'), ...this.$t('city2')]
  109. }, {
  110. text: this.$t('group2'),
  111. children: this.$t('city1')
  112. }, {
  113. text: this.$t('group3'),
  114. children: this.$t('city2')
  115. }, {
  116. text: this.$t('group4'),
  117. disabled: true,
  118. children: this.$t('city3')
  119. }];
  120. }
  121. },
  122. methods: {
  123. onNavClick(index) {
  124. this.mainActiveIndex = index;
  125. },
  126. onItemClick(data) {
  127. this.activeId = data.id;
  128. }
  129. }
  130. };
  131. </script>