简单实现进度条效果(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 小时前
体验家 XMPlus 网页端问卷 SDK 技术解析:用几行 JavaScript 实现精准场景触发与防打扰机制
开发语言·前端·javascript
VidDown5 小时前
VidDown 工具站:视频分辨率技术
javascript·网络·编辑器·音视频·视频编解码·视频
二十七剑5 小时前
LangGraph 源码深度解析:Node 节点 Protocol 与 StateNodeSpec 核心机制
开发语言·python
AC赳赳老秦5 小时前
OpenClaw + 云数据库运维:自动备份、扩容、迁移 RDS/MySQL 云数据库
运维·开发语言·数据库·人工智能·python·mysql·openclaw
醉城夜风~5 小时前
类和对象III
开发语言·c++
冷小鱼5 小时前
高级研发编码习惯:从规范到艺术,再到AI+时代的人机协同
java·开发语言·python·编码习惯
fox_lht5 小时前
15.4.循环和迭代器的性能比较
开发语言·后端·学习·rust
小鹿软件办公5 小时前
倒计时开启:Chromium 宣布几周内将全面切断 MV2 扩展支持
开发语言·javascript·ublock origin
codecrafter1236 小时前
sh:在 Python 里直接调系统命令
开发语言·python·其他
Luminous.6 小时前
C语言--day29
c语言·开发语言