简单实现进度条效果(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>
相关推荐
Wang ruoxi几秒前
Pygame 小游戏——数独
开发语言·python·pygame
人道领域6 分钟前
【LeetCode刷题日记】90.子集Ⅱ--- 归纳题解
java·开发语言·leetcode
云水一下7 分钟前
TypeScript 从零基础到精通(七):从配置到全栈项目落地
前端·javascript·typescript
ch.ju12 分钟前
Java Programming Chapter 4——Characteristics of inheritance
java·开发语言
复园电子14 分钟前
企业PDF批量盖章开发集成指南:API对接OA/LIMS系统,高并发落地实战
开发语言·python·pdf
SunnyDays101118 分钟前
如何使用 C# 自动调整 Excel 行高和列宽
开发语言·c#·excel
a诠释淡然31 分钟前
C++模板元编程—现代C++的黑魔法
开发语言·c++
charlie11451419139 分钟前
现代C++工程:constexpr 基础:编译期求值的艺术
开发语言·c++
十九画生40 分钟前
从同步到异步:重新理解 JavaScript 的执行机制
javascript
半个落月43 分钟前
JavaScript 同步异步与 Promise 详解 —— 从 Event Loop 到手写 sleep
javascript