custom-color.vue 1.5 KB

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