Vue3进度条(Progress)

发布时间:2026/8/29 13:50:22

Vue3进度条(Progress)
Vue2进度条Progress可自定义设置以下属性进度条宽度width单位 px类型string | number默认 undefinedtype: line 时为进度条宽度默认值 100%type: circle 时为进度圈宽高默认值 120当前进度百分比percent类型number默认 0进度条的尺寸lineSize单位 px类型number默认 undefinedtype: line 时为进度条线高默认值 8type: circle 时单位是进度圈画布宽度的百分比默认值 6进度条的色彩lineColor类型string | {0%?: string, 100%?: string, from?: string, to?: string, direction?: left|right}默认 undefined传入 string 时为纯色传入 object 时为渐变进度圈时 direction: left 为逆时针direction: right 为顺时针进度条边缘的形状lineCap类型round | square默认 round是否显示进度数值或状态图标showInfo类型boolean默认 true进度数值或状态图标的尺寸infoSize单位 px类型number默认 undefinedtype: line 时默认值 14type: circle 时默认值 undefined进度完成时的信息success类型string | slot默认 undefined内容的模板函数format类型(percent: number) (string | number) | slot默认(percent: number) percent %进度条类型type类型line | circle默认 line效果如下图在线预览①创建进度条组件Progress.vue其中引入使用了以下工具函数监听插槽存在 useSlotsExist获取依赖注入 useInjectscript setup langts import { computed } from vue import { useSlotsExist, useInject } from components/utils export interface Gradient { 0%?: string 100%?: string from?: string to?: string direction?: left | right // 默认 right } export interface Props { width?: number | string // 进度条宽度单位 pxtype: line 时为进度条宽度默认值 100%type: circle 时为进度圈宽高默认值 120 percent?: number // 当前进度百分比 lineSize?: number // 进度条的尺寸单位 pxtype: line 时为进度条线高默认值 8type: circle 时单位是进度圈画布宽度的百分比默认值 6 lineColor?: string | Gradient // 进度条的色彩传入 string 时为纯色传入 Gradient 时为渐变进度圈时 direction: left 为逆时针direction: right 为顺时针 lineCap?: round | butt // 进度条边缘的形状 showInfo?: boolean // 是否显示进度数值或状态图标 infoSize?: number // 进度数值或状态图标的尺寸单位 pxtype: line 时默认值 14type: circle 时默认值 24 success?: string // 进度完成时的信息 string | slot format?: (percent: number) string | number // 内容的模板函数 function | slot type?: line | circle // 进度条类型 } const props withDefaults(definePropsProps(), { width: undefined, percent: 0, lineSize: undefined, lineColor: undefined, lineCap: round, showInfo: true, infoSize: undefined, success: undefined, format: (percent: number) percent %, type: line }) const { colorPalettes } useInject(Progress) // 主题色注入 const slotsExist useSlotsExist([success]) // 进度条宽度/进度圈宽高 const progressSize computed(() { if (props.width undefined) { if (props.type line) { return 100% } if (props.type circle) { return 120px } } return typeof props.width number ? ${props.width}px : props.width }) // 进度条高度进度圈线宽 const progressLineSize computed(() { if (props.lineSize undefined) { if (props.type line) { return 8 } if (props.type circle) { return 6 } } return props.lineSize as number }) // 进度条/圈进度数值或状态图标尺寸 const progressInfoSize computed(() { if (props.infoSize undefined) { if (props.type line) { return 14px } if (props.type circle) { return 24px } } return ${props.infoSize}px }) // 圆条周长 const perimeter computed(() { return (100 - progressLineSize.value) * Math.PI }) // 圆条轨道路径指令 const path computed(() { const long 100 - progressLineSize.value return M 50,50 m 0,-${long / 2} a ${long / 2},${long / 2} 0 1 1 0,${long} a ${long / 2},${long / 2} 0 1 1 0,-${long} }) // 是否为渐变色 const isGradientColor computed(() { if (props.lineColor ! undefined typeof props.lineColor ! string) { return true } return false }) // 进度条/圈颜色 const lineColorComputed computed(() { if (props.lineColor undefined) { return colorPalettes.value[5] } else if (typeof props.lineColor string) { return props.lineColor } else { return linear-gradient(to ${props.lineColor.direction || right}, ${props.lineColor[0%] || props.lineColor.from}, ${props.lineColor[100%] || props.lineColor.to}) } }) // 进度圈渐变色 id const circleGradient computed(() { if (isGradientColor.value) { const gradientColor props.lineColor as Gradient if (gradientColor.direction undefined || gradientColor.direction right) { return right-${gradientColor[0%] || gradientColor.from}-${gradientColor[100%] || gradientColor.to} } return left-${gradientColor[100%] || gradientColor.to}-${gradientColor[0%] || gradientColor.from} } return null }) const circleColorFrom computed(() { if (isGradientColor.value) { const gradientColor props.lineColor as Gradient if (gradientColor.direction undefined || gradientColor.direction right) { return gradientColor[0%] || gradientColor.from } else { return gradientColor[100%] || gradientColor.to } } return }) const circleColorTo computed(() { if (isGradientColor.value) { const gradientColor props.lineColor as Gradient if (!gradientColor.direction || gradientColor.direction right) { return gradientColor[100%] || gradientColor.to } else { return gradientColor[0%] || gradientColor.from } } return }) const showPercent computed(() { return props.format(props.percent 100 ? 100 : props.percent) }) const showSuccess computed(() { return slotsExist.success || props.success }) /script template div v-iftype line classprogress-line-wrap :style --progress-size: ${progressSize}; --progress-primary-color: ${lineColorComputed}; --progress-success-color: #52c41a; --progress-font-size: ${progressInfoSize}; --progress-border-radius: ${lineCap round ? 100px : 0}; div classprogress-inner div :class[progress-bg, { line-success: percent 100 !isGradientColor }] :stylewidth: ${percent 100 ? 100 : percent}%; height: ${progressLineSize}px; /div /div template v-ifshowInfo Transition namefade modeout-in span v-ifpercent 100 classprogress-success svg v-ifshowSuccess undefined classicon-svg focusablefalse >script setup langts import Progress from ./Progress.vue import { ref } from vue import { MinusOutlined, PlusOutlined } from ant-design/icons-vue import type { ProgressProps } from vue-amazing-ui const percent ref(80) const lineCapOptions [ { label: round, value: round }, { label: butt, value: butt } ] const lineCap refProgressProps[lineCap](butt) function onIncrease(scale: number) { const res percent.value scale if (res 100) { percent.value 100 } else { percent.value res } } function onDecline(scale: number) { const res percent.value - scale if (res 0) { percent.value 0 } else { percent.value res } } /script template div stylewidth: 900px h1{{ $route.name }} {{ $route.meta.title }}/h1 h2 classmt30 mb10基本使用/h2 Progress :percentpercent / h2 classmt30 mb10进度圈/h2 Space aligncenter Progress typecircle :percentpercent / Button clickonDecline(5) sizelarge :iconMinusOutlinedDecline/Button Button clickonIncrease(5) sizelarge :iconPlusOutlinedIncrease/Button /Space h2 classmt30 mb10完成进度条/h2 Flex vertical Progress :percent100 / Progress typecircle :percent100 / /Flex h2 classmt30渐变进度条/h2 h3 classmb10 strokeColor: { 0%: #108ee9, 100%: #87d068, direction: right } 或 { from: #108ee9, to: #87d068, direction: right } /h3 Flex vertical Progress :line-color{ 0%: #108ee9, 100%: #87d068 } :percentpercent / Space aligncenter Progress typecircle :line-color{ 0%: #108ee9, 100%: #87d068 } :percentpercent / Button clickonDecline(5) sizelarge :iconMinusOutlinedDecline/Button Button clickonIncrease(5) sizelarge :iconPlusOutlinedIncrease/Button /Space /Flex h2 classmt30 mb10自定义样式/h2 Flex vertical Progress style--progress-success-color: #ff6900 :line-size24 :line-color{ 0%: #108ee9, 100%: #87d068, direction: left } :info-size24 :percentpercent / Space aligncenter Progress style--progress-success-color: #ff6900 typecircle :width180 :line-size14 :line-color{ 0%: #108ee9, 100%: #87d068, direction: left } :info-size28 :percentpercent / Button clickonDecline(5) sizelarge :iconMinusOutlinedDecline/Button Button clickonIncrease(5) sizelarge :iconPlusOutlinedIncrease/Button /Space /Flex h2 classmt30 mb10自定义边缘形状/h2 Flex vertical Radio :optionslineCapOptions v-model:valuelineCap button button-stylesolid / Progress :line-size20 :line-color{ 0%: white, 100%: pink } :line-caplineCap :info-size20 :percentpercent / Space aligncenter Progress typecircle :width160 :line-size12 :line-color{ 0%: #e3f2fd, 100%: #2080f0 } :line-caplineCap :info-size24 :percentpercent / Button clickonDecline(5) sizelarge :iconMinusOutlinedDecline/Button Button clickonIncrease(5) sizelarge :iconPlusOutlinedIncrease/Button /Space /Flex h2 classmt30 mb10自定义文字/h2 Flex vertical Progress :line-size20 :info-size20 :percentpercent :format(percent: number) $${percent} successDone / Progress style--success-color: #d48806 :line-size20 :info-size20 :percentpercent template #format{ percent } span stylecolor: #d4380d{{ percent }}%/span /template template #success span stylecolor: #d48806Bingo/span /template /Progress Space aligncenter Progress typecircle :width160 :line-size12 :info-size24 :percentpercent :format(percent: number) ${percent} Days successDone / Progress style--success-color: #d48806 typecircle :width160 :line-size12 :info-size24 :percentpercent template #format{ percent } span stylecolor: #d4380d{{ percent }}%/span /template template #success span stylecolor: #d48806Bingo/span /template /Progress Button clickonDecline(5) sizelarge :iconMinusOutlinedDecline/Button Button clickonIncrease(5) sizelarge :iconPlusOutlinedIncrease/Button /Space /Flex /div /template

相关新闻

Vue3分割线(Divider)

Vue3分割线(Divider)

2026/8/29 13:50:22

可自定义设置以下属性: 分割线标题的位置(orientation),类型:left | center | right,默认 center 标题和最近 left/right 边框之间的距离,去除了分割线,同时 orientation 必须为 le…

2026年ai建站哪家技术强,多平台对比来啦!

2026年ai建站哪家技术强,多平台对比来啦!

2026/8/29 13:50:22

2026年ai建站哪家技术强,多平台对比来啦!艾瑞咨询《2026年中国企业数字化建站行业白皮书》给出一组对照:国内AI建站渗透率已破68%,但抽样超1200家中小企业中仅31%在AI生成站点半年后仍持续续费且搜索流量正向增长。 深圳某3C配件品…

千问赢在生态:本地部署、开发者集成与办公场景全解析

千问赢在生态:本地部署、开发者集成与办公场景全解析

2026/8/29 13:50:22

看到“苹果删了千问,但阿里赢了”这个说法时,我第一反应不是去考证事件细节,而是想另一个问题:一个 AI 产品如果只是失去某个渠道入口,为什么还能被这么多人继续讨论?千问给出的答案,不是把流量…

PowerToys File Locksmith:文件删不掉时,先查清哪个进程占着它

PowerToys File Locksmith:文件删不掉时,先查清哪个进程占着它

2026/8/29 15:00:25

PowerToys File Locksmith:文件删不掉时,先查清哪个进程占着它 【免费下载链接】PowerToys Microsoft PowerToys is a collection of utilities that supercharge productivity and customization on Windows 项目地址: https://gitcode.com/GitHub_Tr…

AGENTS.md 兼容性隐患:如何让 Claude Code 稳定遵循项目规则

AGENTS.md 兼容性隐患:如何让 Claude Code 稳定遵循项目规则

2026/8/29 15:00:25

最近技术社区讨论度最高的话题之一,是 Shopify CEO 在内部推动评估禁用 Claude Code,理由是它对 AGENTS.md 的执行不够可靠。这则消息很快引发了连锁讨论,因为很多团队正好卡在同一个问题上:AI 编码工具越来越强,但项目…

GrandDog_Driver工业USB驱动SDK深度解析

GrandDog_Driver工业USB驱动SDK深度解析

2026/8/29 15:00:25

简介:本资源为GrandDog设备专用驱动程序1.0.35.3发布候选版(RC),面向嵌入式开发工程师、硬件调试人员及驱动适配技术人员,解决GrandDog加密狗或安全模块在Windows平台下的识别异常、通信不稳定及新版系统兼容性问题。压…

前臂肌电信号控制机械手:从信号采集到动作映射的完整DIY指南

前臂肌电信号控制机械手:从信号采集到动作映射的完整DIY指南

2026/8/29 15:00:25

1. 项目概述与思路拆解 1.1 项目定位:不只是“做一个机械手” 我第一次看到“Forearm-Controlled Robotic Hand”这个标题时,第一反应是:终于有人走对方向了。市面上的机械手项目太多,但绝大多数用的是手机App控制、体感手套甚至…

AI测试岗别再想混进去:本地实操验证能力的完整指南

AI测试岗别再想混进去:本地实操验证能力的完整指南

2026/8/29 15:00:25

这次我们聊一个很现实的职场话题:AI测试岗,到底能不能“先混进去再说”。这个说法在测试圈里流传挺广,尤其是在大模型、AIGC 相关岗位热度上来之后。很多人觉得,反正 AI 测试也是点点点、跑跑用例,只要进去了再学也不迟…

Tesseract 源码编译部署实战:选对分支,1 小时跑通第一条 OCR

Tesseract 源码编译部署实战:选对分支,1 小时跑通第一条 OCR

2026/8/29 14:50:25

Tesseract 源码编译部署实战:选对分支,1 小时跑通第一条 OCR 【免费下载链接】tesseract Tesseract Open Source OCR Engine (main repository) 项目地址: https://gitcode.com/GitHub_Trending/te/tesseract 这篇文章解决一件事:在一…

[光学原理与应用-521]:对光的错误理解与纠偏

[光学原理与应用-521]:对光的错误理解与纠偏

2026/8/27 11:10:02

首先光是一种能量的载体和形态,宏观上观察到的光是由无数个微观的光量子组成的,每个光子在产生的瞬间,其在真空的空间中以确定不变的速度沿着一个初始的方向一直向前,在微观层面,每个光量子的运动轨迹是以波函数所展现…

SIP通话转接原理与REFER方法实战解析

SIP通话转接原理与REFER方法实战解析

2026/8/29 10:22:10

1. 通话转接不是“挂断再拨号”,而是SIP会话的动态重定向你有没有遇到过这样的场景:客服坐席A正在和客户通电话,突然需要把这通对话无缝转给专家坐席B,客户完全感知不到中间的断连——既没听到忙音,也没被要求重新拨号…

Kolla-ansible单节点OpenStack部署实战:从环境准备到排坑指南

Kolla-ansible单节点OpenStack部署实战:从环境准备到排坑指南

2026/8/28 7:34:42

1. 为什么选择Kolla-ansible来部署单节点OpenStack?如果你正在寻找一种能把OpenStack从“概念”快速变成“可用的实验环境”的方法,那么Kolla-ansible几乎是当前最主流、最省心的选择。我见过太多人卡在手动编译依赖、配置服务、处理版本冲突的泥潭里&am…

四款热门降AI工具测评:研究生和本科生怎么选?

四款热门降AI工具测评:研究生和本科生怎么选?

2026/8/29 0:09:39

马上要交论文了,最近真的被论文ai率折磨的够呛。 明明查重都没问题了,但是ai率就是居高不下,崩溃了,明明都是我自己写的,天杀的,明明都是我亲生的啊 改来改去,终于给我搞出一套完美的降ai方案…

论文降AI率免费攻略:自查、提示词与工具推荐

论文降AI率免费攻略:自查、提示词与工具推荐

2026/8/29 0:09:39

马上要交论文了,最近真的被论文ai率折磨的够呛。 明明查重都没问题了,但是ai率就是居高不下,崩溃了,明明都是我自己写的,天杀的,明明都是我亲生的啊 改来改去,终于给我搞出一套完美的降ai方案…

北京GEO优化服务商推荐:预算型企业如何选北京GEO优化服务商?

北京GEO优化服务商推荐:预算型企业如何选北京GEO优化服务商?

2026/8/29 0:09:39

前言:预算有限的企业更关心投入能否形成可持续的品牌资产。评估北京GEO优化服务商时,不能只比较单篇内容或单月报价,还要看是否能够把问题词、官网、信源和监测串成完整链路。本期重点放在预算配置、试点范围和交付边界,帮助企业先…

摆脱论文困扰!盘点2026年全网爆红的的AI论文写作工具

摆脱论文困扰!盘点2026年全网爆红的的AI论文写作工具

2026/8/28 7:35:26

一天写完毕业论文在2026年已不再是天方夜谭。2026年最炸裂、实测能大幅提速的AI论文写作工具,覆盖选题构思、文献整理、内容生成、格式排版等核心场景,真正帮你高效搞定论文难题。 一、全流程王者:一站式搞定论文全链路(一天定稿首…

导师推荐!2026最新AI论文工具测评与实用推荐

导师推荐!2026最新AI论文工具测评与实用推荐

2026/8/28 7:34:51

2026年真正好用的AI论文工具,核心看生成的论文质量、低AI味、格式正确、学术适配四大指标。综合实测,千笔AI、ThouPen、豆包、DeepSeek、Grammarly 是当前最值得推荐的梯队,覆盖从免费到付费、从中文到英文、从文科到理工的全场景需求。 一、…

告别游戏崩溃:XCOM 2模组管理器的智能革命

告别游戏崩溃:XCOM 2模组管理器的智能革命

2026/8/28 7:34:35

告别游戏崩溃:XCOM 2模组管理器的智能革命 【免费下载链接】xcom2-launcher The Alternative Mod Launcher (AML) is a replacement for the default game launchers from XCOM 2 and XCOM Chimera Squad. 项目地址: https://gitcode.com/gh_mirrors/xc/xcom2-lau…