vue实现环形百分比进度条组件

本文介绍如何使用Vue实现一个环形百分比进度条组件,包括组件的调用示例和拓展属性的添加,同时提及了icon组件的封装情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考网上的一些环形百分比进度展示,加了一些拓展属性~

下面为两个调用的实例效果~

icon组件为另外封装的,可自行删除修改

组件调用

<radial-indicator 
    percentNum="87"
    speed="3"
    size="155"
    color="#8abf50"
    @animationFinished="animationFinished"
    backgroundColor="#c4dfa7"
    content="平均送达率"
    icon="mail"
/>

组件封装

<template>
  <div class="radial-indicator-container" :style="{'width':size+'px','height':size+'px'}">
    <div class="percentloop">
      <div class="circle-left" :style="{ backgroundColor: color}">
        <div :style="{ backgroundColor: backgroundColor}" ref="leftcontent"></div>
      </div>
      <div class="circle-right" :style="{ backgroundColor: color}">
        <div :styl
### 创建半环形进度条组件 #### 半环形进度条实现思路 为了在 Vue 中创建一个半环形进度条组件,可以基于 SVG 的路径绘制来完成。主要原理是通过设置 `stroke-dasharray` 和 `stroke-dashoffset` 属性控制显示的部分圆弧长度[^4]。 #### HalfCircleProgress.vue 组件代码 下面是一个简单的半环形进度条组件示例: ```vue <template> <div class="half-circle-progress"> <svg viewBox="-1 -1 2 2" style="width: 80px; height: 40px;"> <!-- 背景半圆 --> <path d="M 0,1 a 1,.5 0 0 1 0,-1" stroke="#ebebeb" fill="none"/> <!-- 前景色半圆 --> <path :d="arcDescriptor" :style="{strokeDasharray: `${dashArray}, ${totalLength}`, strokeDashoffset}" stroke-linecap="round" stroke-width=".1" fill="none" /> </svg> <span>{{ percentage }}%</span> </div> </template> <script> export default { props: [&#39;percentage&#39;], data() { return { totalLength: Math.PI, dashArray: null, strokeOffset: null } }, computed: { arcDescriptor() { const radiusX = 1; const radiusY = .5; return `M 0,${radiusY} a ${radiusX},${radiusY} 0 0 1 0,-${2 * radiusY}`; }, strokeDashoffset() { this.dashArray = (this.percentage / 100) * this.totalLength; return this.totalLength - this.dashArray; } } } </script> <style scoped> .half-circle-progress span { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); font-size: 1rem; } </style> ``` 此组件接受一个百分比作为属性输入,并据此调整前景区的颜色填充程度。 #### 父组件调用方式 可以在父组件中像这样引入并使用上述定义好的 `<HalfCircleProgress>` 组件: ```html <half-circle-progress :percentage="progressValue"></half-circle-progress> ``` 其中 `progressValue` 是用于绑定到子组件的数据项,表示当前进度值[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值