环形进度条

时间:2021-09-22
本文章向大家介绍环形进度条,主要包括环形进度条使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

ProjressCircle.vue

<template>
  <div class="progress-circle">
    <svg :width="size" :height="size" viewBox="0 0 100 100">
      <circle r="50" cx="50" cy="50" fill="transparent" class="progress-background"></circle>
      <circle r="50" cx="50" cy="50" fill="transparent" class="progress-bar" :stroke-dasharray="dashArray" :stroke-dashoffset="dashOffset"></circle>
    </svg>
  </div>
</template>

<script>
export default {
  props: {
    size: { type: Number, default: 100 },
    percent: { type: Number, default: 0 }
  },
  data() {
    return { dashArray: Math.PI * 2 * 50 }
  },
  computed: {
    dashOffset() {
      return (1 - this.percent) * this.dashArray
    }
  }
}
</script>

<style scoped>
circle {
  stroke-width: 10px;
  transform-origin: center;
}
.progress-background {
  transform: scale(0.9);
  stroke: rgba(66, 66, 66, 0.5);
}
.progress-bar {
  stroke: greenyellow;
  transform: rotate(-90deg) scale(0.9);
}
</style>

使用:

    <ProjressCircle :size="100" :percent="0.2"></ProjressCircle>

效果:

原文地址:https://www.cnblogs.com/wuqilang/p/15320959.html