demo5.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <div class="demo-progress">
  3. <m-progress type="dashboard" :percentage="percentage" :color="colors" />
  4. <m-progress type="dashboard" :percentage="percentage2" :color="colors" />
  5. <div>
  6. <m-button leftIcon="icon-minus" @click="decrease" />
  7. <m-button leftIcon="icon-add" @click="increase" />
  8. </div>
  9. </div>
  10. </template>
  11. <script setup>
  12. import { onMounted, ref } from 'vue-demi'
  13. const percentage = ref(10)
  14. const percentage2 = ref(0)
  15. const colors = [
  16. { color: '#f56c6c', percentage: 20 },
  17. { color: '#e6a23c', percentage: 40 },
  18. { color: '#5cb87a', percentage: 60 },
  19. { color: '#1989fa', percentage: 80 },
  20. { color: '#6f7ad3', percentage: 100 },
  21. ]
  22. const increase = () => {
  23. percentage.value += 10
  24. if (percentage.value > 100) {
  25. percentage.value = 100
  26. }
  27. }
  28. const decrease = () => {
  29. percentage.value -= 10
  30. if (percentage.value < 0) {
  31. percentage.value = 0
  32. }
  33. }
  34. onMounted(() => {
  35. setInterval(() => {
  36. percentage2.value = (percentage2.value % 100) + 10
  37. }, 500)
  38. })
  39. </script>
  40. <style scoped>
  41. .demo-progress .m-progress--dashboard {
  42. margin:0 15px 15px 0;
  43. }
  44. </style>