index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <demo-section>
  3. <demo-block :title="$t('basicUsage')">
  4. <van-circle
  5. v-model="currentRate1"
  6. :rate="rate"
  7. :speed="100"
  8. size="120px"
  9. :text="currentRate1.toFixed(0) + '%'"
  10. />
  11. <van-circle
  12. v-model="currentRate2"
  13. color="#07c160"
  14. fill="#fff"
  15. :rate="rate"
  16. size="120px"
  17. layer-color="#ebedf0"
  18. :speed="100"
  19. :stroke-width="60"
  20. :clockwise="false"
  21. :text="currentRate2.toFixed(0) + '%'"
  22. />
  23. <div>
  24. <van-button
  25. :text="$t('add')"
  26. type="primary"
  27. size="small"
  28. @click="add"
  29. />
  30. <van-button
  31. :text="$t('decrease')"
  32. type="danger"
  33. size="small"
  34. @click="reduce"
  35. />
  36. </div>
  37. </demo-block>
  38. </demo-section>
  39. </template>
  40. <script>
  41. const format = rate => Math.min(Math.max(rate, 0), 100);
  42. export default {
  43. i18n: {
  44. 'zh-CN': {
  45. title2: '样式定制'
  46. },
  47. 'en-US': {
  48. title2: 'Custom Style'
  49. }
  50. },
  51. data() {
  52. return {
  53. rate: 30,
  54. currentRate1: 0,
  55. currentRate2: 0
  56. };
  57. },
  58. methods: {
  59. add() {
  60. this.rate = format(this.rate + 20);
  61. },
  62. reduce() {
  63. this.rate = format(this.rate - 20);
  64. }
  65. }
  66. };
  67. </script>
  68. <style lang="less">
  69. .demo-circle {
  70. .van-circle {
  71. margin-left: 15px;
  72. }
  73. .van-button {
  74. margin: 15px 0 0 10px;
  75. &:first-of-type {
  76. margin-left: 15px;
  77. }
  78. }
  79. }
  80. </style>