index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <demo-section>
  3. <demo-block :title="$t('title1')">
  4. <van-slider
  5. v-model="value1"
  6. @change="onChange"
  7. />
  8. </demo-block>
  9. <demo-block :title="$t('title2')">
  10. <van-slider
  11. v-model="value2"
  12. :min="10"
  13. :max="90"
  14. @change="onChange"
  15. />
  16. </demo-block>
  17. <demo-block :title="$t('title3')">
  18. <van-slider
  19. v-model="value3"
  20. disabled
  21. />
  22. </demo-block>
  23. <demo-block :title="$t('title4')">
  24. <van-slider
  25. v-model="value4"
  26. :step="10"
  27. @change="onChange"
  28. />
  29. </demo-block>
  30. <demo-block :title="$t('customStyle')">
  31. <van-slider
  32. v-model="value5"
  33. bar-height="4px"
  34. active-color="#f44"
  35. @change="onChange"
  36. />
  37. </demo-block>
  38. <demo-block :title="$t('customButton')">
  39. <van-slider
  40. v-model="value6"
  41. active-color="#f44"
  42. >
  43. <div
  44. slot="button"
  45. class="custom-button"
  46. >
  47. {{ value6 }}
  48. </div>
  49. </van-slider>
  50. </demo-block>
  51. <demo-block
  52. v-if="!$attrs.weapp"
  53. :title="$t('vertical')"
  54. >
  55. <div :style="{ height: '120px', paddingLeft: '30px' }">
  56. <van-slider
  57. v-model="value7"
  58. vertical
  59. @change="onChange"
  60. />
  61. </div>
  62. </demo-block>
  63. </demo-section>
  64. </template>
  65. <script>
  66. export default {
  67. i18n: {
  68. 'zh-CN': {
  69. title1: '基本用法',
  70. title2: '指定选择范围',
  71. title3: '禁用',
  72. title4: '指定步长',
  73. customStyle: '自定义样式',
  74. customButton: '自定义按钮',
  75. text: '当前值:',
  76. vertical: '垂直方向'
  77. },
  78. 'en-US': {
  79. title1: 'Basic Usage',
  80. title2: 'Range',
  81. title3: 'Disabled',
  82. title4: 'Step size',
  83. customStyle: 'Custom Style',
  84. customButton: 'Custom Button',
  85. text: 'Current value: ',
  86. vertical: 'Vertical'
  87. }
  88. },
  89. data() {
  90. return {
  91. value1: 50,
  92. value2: 50,
  93. value3: 50,
  94. value4: 50,
  95. value5: 50,
  96. value6: 50,
  97. value7: 50
  98. };
  99. },
  100. methods: {
  101. onChange(value) {
  102. this.$toast(this.$t('text') + value);
  103. }
  104. }
  105. };
  106. </script>
  107. <style lang="less">
  108. @import '../../style/var';
  109. .demo-slider {
  110. user-select: none;
  111. .van-slider {
  112. margin: 0 15px 30px;
  113. }
  114. .custom-button {
  115. width: 26px;
  116. color: #fff;
  117. font-size: 10px;
  118. line-height: 18px;
  119. text-align: center;
  120. border-radius: 100px;
  121. background-color: @red;
  122. }
  123. .van-doc-demo-block__title {
  124. padding-top: 25px;
  125. }
  126. }
  127. </style>