简单实现进度条效果(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>
相关推荐
jllllyuz14 分钟前
MATLAB 回声抵消(AEC)、噪声抑制(NS)、自动增益控制(AGC)完整实现
开发语言·matlab
froginwe1115 分钟前
Vue.js 计算属性
开发语言
05候补工程师22 分钟前
【408 从零到一】线性表逻辑特征、存储结构对比与 C/C++ 动态内存分配避坑指南
c语言·开发语言·数据结构·c++·考研
空中海30 分钟前
03 渲染机制、性能优化与现代 React
javascript·react.js·性能优化
yongui4783430 分钟前
MATLAB 使用遗传算法求解微电网优化配置数学模型
开发语言·matlab
郝学胜-神的一滴33 分钟前
Python 抽象基类深度解析:从简易模拟到 abc 模块的优雅实践
开发语言·python·pycharm
Python伍六七1 小时前
给予Python开发的【16款高效办公自动化工具合集】,告别低效加班!
开发语言·python·自动化
rit84324991 小时前
基于博弈论的小区分簇算法MATLAB实现
开发语言·算法·matlab
ChalesXavier1 小时前
Fetch API 的基本用法
javascript
怕什么真理无穷1 小时前
C++面试5_ TCP 粘包2(工业级)
开发语言·c++·tcp/ip