vue中封装一个进度条组件,无需引入,纯css

效果图是这样

下面直接上组件代码

html 复制代码
<template>
  <div 
    class="gradient-progress" 
    :style="{ '--progress': percent + '%', '--main-color': color }"
  ></div>
</template>

<script>
export default {
  props: {
    percent: { type: Number, default: 0, min: 0, max: 100 },
    color: { type: String, default: '#ff4444' }
  }
}
</script>

<style scoped>
.gradient-progress {
  --bg-color: #e0e0e0;
  width: 100%;
  height: 6px;
  background: var(--bg-color);
  /* border-radius: 999px; */
  overflow: hidden;
  position: relative;
}
.gradient-progress::after {
  content: '';
  position: absolute;
  left: 0; top: 0;
  height: 100%;
  width: var(--progress);
  background: linear-gradient(to right, 
    var(--main-color), 
    color-mix(in srgb, var(--main-color), white 50%)
  );
  /* border-radius: 999px; */
  transition: width 0.3s ease;
}
</style>

使用的时候也非常简单,引入组件后传入颜色以及进度就可以了

<GradientProgress :percent="60" color="#3273d8" class="progress" />

相关推荐
我有满天星辰36 分钟前
Vue 指令完全指南:从 Vue 2 到 Vue 3 的演进与实战
前端·javascript·vue.js
小白学过的代码39 分钟前
# flv.js / mpegts.js 播不了国标摄像头(H.265 + G.711A)?纯前端 Jessibuca 无后端方案(附完整代码)
前端·javascript·h.265
我有满天星辰3 小时前
Vue 3 响应式双雄:ref 与 reactive 完全指南
前端·javascript·vue.js
随风一样自由12 小时前
【前端独角兽】刚进入前端领域的前端开发用jQuery还是Vue3?
前端·javascript·vue3·jquery
YHHLAI13 小时前
[特殊字符] 面试中的 Promise —— 从入门到精通
前端·javascript·面试
weixin_BYSJ198713 小时前
SpringBoot + MySQL 乒乓球运动员信息管理系统项目实战--附源码04954
java·javascript·spring boot·python·django·flask·php
沪飘大军14 小时前
ll-llm:一个零依赖、可插拔的 OpenAI 兼容 LLM 代理
javascript
leoZ23114 小时前
Claude 驱动的全栈开发:Spring Boot + Vue 的 BS 架构实践
vue.js·spring boot·架构
山河木马15 小时前
GPU自动处理专题3-NDC怎么映射成屏幕像素坐标(视口变换)
javascript·webgl·图形学
Appthing17 小时前
在 TanStack Start 中使用 VitePWA 的正确配置
javascript