简单实现进度条效果(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>
相关推荐
云中飞鸿7 分钟前
.Net和C#有什么关系?(从C++视角观察)
开发语言·c#·.net
another heaven8 分钟前
【C/C++ C++ 新特性中的那些内存优化的特性】
c语言·开发语言·c++
Wang's Blog10 分钟前
Java 项目实战: 交友项目 - 查询推荐动态
java·开发语言·交友
jaysee-sjc16 分钟前
【苍穹外卖】Day10:定时任务与 WebSocket 实时提醒实战
java·开发语言·javascript·数据库·vue.js·websocket·网络协议
ysu_031419 分钟前
【C++ 进阶之路】(二)从内联函数到类与对象:深挖内存对齐、this 指针与三大默认成员函数
开发语言·数据结构·c++·笔记·面向对象·this
独隅20 分钟前
Claude 高效应用实战指南
android·java·开发语言·claude·claude code
布莱克60525 分钟前
C++ 中 set 与 map 的区别详解
开发语言·c++·算法·哈希
Wang's Blog44 分钟前
Java 项目实战: 交友项目 - 圈子互动
java·开发语言·交友
尤水就下1 小时前
🔥说一说在线文档的 Block 架构是如何实现的
前端·javascript·架构
jimy11 小时前
构造函数表达式的值类别是:prvalue
开发语言·c++