简单实现进度条效果(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>
相关推荐
richard_yuu39 分钟前
C#零基础通关第六篇:吃透静态、常量与只读,分清静态与实例的本质差异
开发语言·c#
拂拉氏2 小时前
【项目分享-知识讲解】C++标准库string类的模拟实现+KMP算法讲解+哈希思想了解
开发语言·c++·算法·kmp算法·哈希·string类
枫叶丹42 小时前
【HarmonyOS 6.0】Graphics Accelerate Kit:AI超帧能力技术解析与实践
开发语言·人工智能·华为·harmonyos
HelloAldis2 小时前
Java 库 univer-lib:让 Univer Sheets 与 xlsx 无损双向转换
java·开发语言·xlsx·univer
枕星而眠2 小时前
C++ 类与对象核心知识点及面试高频题详解
开发语言·c++·面试
2501_930707788 小时前
使用C#代码在 PowerPoint 中组合或取消组合形状
开发语言·c#
晚烛8 小时前
CANN 调试工具与性能剖析:从日志分析到 NPU 行为追踪的完整调试体系
开发语言·windows·python·深度学习·缓存
惊鸿一博8 小时前
图标加载方式_zeroIcon_是否加前缀mdi
开发语言·前端·javascript
森G8 小时前
TypeScript 基础类型
开发语言·typescript
你很易烊千玺8 小时前
JS 异步 从零讲(大白话 + 真实场景 + 可运行案例)
前端·javascript·vue.js