简单实现进度条效果(vue2)

如果用echarts或者其他图表来写个进度条有点大材小用,所以直接简单html、js写一下就可以;

以下代码基于vue2,

部分代码来自国内直连GPT/Claude镜像站

javascript 复制代码
<template>
  <div class="progress-container">
    <div class="progress-item" v-for="(item, index) in progressData" :key="index">
      <div class="label">{{ item.label }}</div>
      <div class="progress-bar">
        <div class="progress" :style="{ width: item.value + '%', backgroundColor: item.color }">
          <span class="value">{{ item.value }}%</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ProgressChart',
  data() {
    return {
      progressData: [
        { label: '当前值', value: 15, color: '#ff4757' },
        { label: '设计值', value: 8, color: '#2ed573' }
      ]
    }
  },
}
</script>

<style scoped>
.progress-container {
  background-color: #1e3a5f;
  padding: 10px;
}
.progress-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
.label {
  width: 60px;
  color: #fff;
  font-size: 14px;
}
.progress-bar {
  flex-grow: 1;
  height: 20px;
  background-color: #2c4d6f;
  margin: 0 10px;
  position: relative;
}
.progress {
  height: 100%;
  transition: width 0.5s ease-in-out;
  position: relative;
}
.value {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  color: #fff;
  font-size: 14px;
}
</style>
相关推荐
阿里嘎多学长5 分钟前
2026-03-27 GitHub 热点项目精选
开发语言·程序员·github·代码托管
菜菜小狗的学习笔记11 分钟前
Java SE(一)内部类、Lambda表达式、Stream流
java·开发语言
码云数智-园园12 分钟前
Java中的重载(Overload)与重写(Override):本质区别、场景与注意事项
java·开发语言
yxm263366908113 分钟前
洛谷P1217回文质数
java·开发语言
金斗潼关13 分钟前
java反序列化入口方法介绍
java·开发语言·jvm·序列化·反序列化
量子炒饭大师13 分钟前
【C++模板进阶】——【非类型模板参数 / 模板的特化 / 模板分离编译】
开发语言·c++·dubbo·模板·非类型模板·模板的特化·模板分离编译
雨师@15 分钟前
python包uv使用介绍
开发语言·python·uv
吴声子夜歌16 分钟前
JavaScript——异步编程
开发语言·前端·javascript
武藤一雄17 分钟前
C# 核心技术解析:Parse vs TryParse 实战指南
开发语言·windows·microsoft·微软·c#·.netcore
一直都在57218 分钟前
Java并发面经(二)
java·开发语言·spring