ProgressRing.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <svg :height="radius * 2" :width="radius * 2">
  3. <circle
  4. :stroke-width="stroke"
  5. class="stroke-green-500"
  6. fill="transparent"
  7. :r="normalizedRadius"
  8. :cx="radius"
  9. :cy="radius"
  10. />
  11. <circle
  12. :stroke-width="stroke"
  13. stroke="currentColor"
  14. fill="transparent"
  15. :r="normalizedRadius"
  16. :cx="radius"
  17. :cy="radius"
  18. :style="{ strokeDashoffset: strokeDashoffset }"
  19. :stroke-dasharray="circumference + ' ' + circumference"
  20. />
  21. </svg>
  22. </template>
  23. <script>
  24. import { defineComponent } from "@nuxtjs/composition-api"
  25. export default defineComponent({
  26. props: {
  27. radius: {
  28. type: Number,
  29. default: 12,
  30. },
  31. progress: {
  32. type: Number,
  33. default: 50,
  34. },
  35. stroke: {
  36. type: Number,
  37. default: 4,
  38. },
  39. },
  40. data() {
  41. const normalizedRadius = this.radius - this.stroke * 2
  42. const circumference = normalizedRadius * 2 * Math.PI
  43. return {
  44. normalizedRadius,
  45. circumference,
  46. }
  47. },
  48. computed: {
  49. strokeDashoffset() {
  50. return this.circumference - (this.progress / 100) * this.circumference
  51. },
  52. },
  53. })
  54. </script>