简单实现进度条效果(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>
相关推荐
AI街潜水的八角6 小时前
Python电脑屏幕&摄像头录制软件(提供源代码)
开发语言·python
hadage2336 小时前
--- git 的一些使用 ---
开发语言·git·python
Lhuu(重开版8 小时前
CSS:动效布局动画
前端·css
lly2024068 小时前
HTML与CSS:构建网页的基石
开发语言
一只会写代码的猫8 小时前
面向高性能计算与网络服务的C++微内核架构设计与多线程优化实践探索与经验分享
java·开发语言·jvm
2013编程爱好者9 小时前
Vue工程结构分析
前端·javascript·vue.js·typescript·前端框架
是小胡嘛9 小时前
C++之Any类的模拟实现
linux·开发语言·c++
csbysj202010 小时前
Vue.js 混入:深入理解与最佳实践
开发语言
不羁的fang少年11 小时前
前端常见问题(vue,css,html,js等)
前端·javascript·css
change_fate11 小时前
el-menu折叠后文字下移
前端·javascript·vue.js