简单实现进度条效果(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>
相关推荐
w_zero_one21 分钟前
递归算法(一)
java·开发语言·算法
OpsEye39 分钟前
大模型 Token 计量不准,是什么原因,怎么解决??
javascript·ai编程
Julien20041 小时前
管理机密(一)
运维·服务器·开发语言·学习方法
Chen_harmony1 小时前
七、STL与string类
开发语言·c++
沐晓时光2 小时前
C语言入门,字符串和字符串函数知识讲解
c语言·开发语言
xxxiugou1232 小时前
C++命名空间与引用全解析
开发语言·c++
用户3434612783202 小时前
用户认证系统在高并发下的幂等性与限流策略踩坑实录
css
独隅2 小时前
WebStorm Windows 版 React / Next.js 实战替换指南
javascript·windows·webstorm
冷眸_2 小时前
同名食材不能直接相减:一个 JavaScript 用量模型的边界
javascript
apollo_qwe3 小时前
接口超时了,前端为什么不能直接重试?
javascript·http