简单实现进度条效果(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>
相关推荐
潼心1412o9 小时前
C++初阶(长期更新)第5讲:类和对象(中)
开发语言·c++
weixin_307779139 小时前
C++代码实现MATLAB中的normalize函数功能
开发语言·c++·算法·matlab
谢亮_vipxieliang9 小时前
Go WaitGroup与Once——并发同步的基石
开发语言·后端·golang
ITOM运维行者9 小时前
PHP性能监控怎么做?从响应时间到慢函数的6个关键指标
前端·javascript·后端
程序员老陆9 小时前
通过std::unique_ptr初始化std::shared_ptr
开发语言·c++
liangshanbo121510 小时前
前端面试题:AI 对话中超长消息导致内存溢出,怎么解决?
java·开发语言·前端
hai_android10 小时前
一个公式看懂动态跨表查找:P8 + VLOOKUP
前端·javascript·vue.js
北冥you鱼10 小时前
Go 语言 Channel 机制详解:从原理到实战
开发语言·后端·golang
杨利杰YJlio10 小时前
Tibo的28天计划DAY1GPT-6提速50%意味着什么?
前端·javascript·后端
谢亮_vipxieliang10 小时前
Go 并发控制进阶:sync 包高级原语与 Context 生命周期管理
开发语言·后端·golang