简单实现进度条效果(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>
相关推荐
Yeniden4 分钟前
Deepeek用大白话讲解 --> 迭代器模式(企业级场景1,多种遍历方式2,隐藏集合结构3,Java集合框架4)
java·开发语言·迭代器模式
SmoothSailingT13 分钟前
C#——LINQ方法
开发语言·c#·linq
景川呀13 分钟前
Java的类加载器
java·开发语言·java类加载器
k***921617 分钟前
Python 科学计算有哪些提高运算速度的技巧
开发语言·python
superman超哥17 分钟前
仓颉条件变量深度解析与实践:解锁高效并发同步
开发语言·python·c#·仓颉
道法自然|~1 小时前
【PHP】简单的脚本/扫描器拦截与重要文件保护
开发语言·爬虫·php
dly_blog1 小时前
setup 函数完整指南!
前端·javascript·vue.js
GoWjw1 小时前
在C&C++中结构体的惯用方法
c语言·开发语言·c++
霍理迪1 小时前
基础CSS语法
前端·css
静心观复1 小时前
Java 中,`1 << 1`
java·开发语言