简单实现进度条效果(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>
相关推荐
winfredzhang3 分钟前
使用Python和Selenium打造一个全网页截图工具
开发语言·python·selenium
mahuifa11 分钟前
(10)python开发经验
开发语言·python
阿珊和她的猫12 分钟前
Vue Router中的路由嵌套:主子路由
前端·javascript·vue.js
_龙小鱼_20 分钟前
Kotlin扩展简化Android动画开发
android·开发语言·kotlin
霸王蟹25 分钟前
React 19中如何向Vue那样自定义状态和方法暴露给父组件。
前端·javascript·学习·react.js·typescript
小伍_Five26 分钟前
spark数据处理练习题详解【上】
java·开发语言·spark·scala
mascon36 分钟前
C#自定义扩展方法 及 EventHandler<TEventArgs> 委托
开发语言·c#
shenyan~1 小时前
关于 js:9. Node.js 后端相关
前端·javascript·node.js
Evand J1 小时前
【MATLAB例程】线性卡尔曼滤波的程序,三维状态量和观测量,较为简单,可用于理解多维KF,附代码下载链接
开发语言·matlab
苕皮蓝牙土豆1 小时前
C++ map容器: 插入操作
开发语言·c++