demo3.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <div class="demo-progress">
  3. <m-progress :percentage="percentage" :color="customColor" />
  4. <m-progress :percentage="percentage" :color="customColorMethod" />
  5. <m-progress :percentage="percentage" :color="customColors" />
  6. <div>
  7. <m-button leftIcon="icon-minus" @click="decrease" />
  8. <m-button leftIcon="icon-add" @click="increase" />
  9. </div>
  10. </div>
  11. </template>
  12. <script setup>
  13. import { ref } from 'vue-demi'
  14. const percentage = ref(20)
  15. const customColor = ref('#409eff')
  16. const customColors = [
  17. { color: '#f56c6c', percentage: 20 },
  18. { color: '#e6a23c', percentage: 40 },
  19. { color: '#5cb87a', percentage: 60 },
  20. { color: '#1989fa', percentage: 80 },
  21. { color: '#6f7ad3', percentage: 100 },
  22. ]
  23. const customColorMethod = (percentage) => {
  24. if (percentage < 30) {
  25. return '#909399'
  26. }
  27. if (percentage < 70) {
  28. return '#e6a23c'
  29. }
  30. return '#67c23a'
  31. }
  32. const increase = () => {
  33. percentage.value += 10
  34. if (percentage.value > 100) {
  35. percentage.value = 100
  36. }
  37. }
  38. const decrease = () => {
  39. percentage.value -= 10
  40. if (percentage.value < 0) {
  41. percentage.value = 0
  42. }
  43. }
  44. </script>
  45. <style scoped>
  46. .demo-progress .m-progress--line {
  47. margin-bottom: 15px;
  48. width: 350px;
  49. }
  50. </style>