简单实现进度条效果(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>
相关推荐
赵得C1 分钟前
创建 SVG 图标预览页面:从零实现到解决 CORS 问题
前端·javascript·html
Brilliantwxx9 分钟前
【STM32】 __weak 弱引用、中断标志位、异常处理与 HAL_Delay 优先级
开发语言·stm32·单片机·嵌入式硬件
驭渊的小故事10 分钟前
SpringBoot 配置文件详解:properties 与 yml 从入门到实战
java·开发语言·笔记
peter676824 分钟前
css学习小结
前端·css·学习
liangshanbo121525 分钟前
什么是CSS原子化?它的优劣势是什么?
前端·css·tensorflow·css原子化
郝学胜-神的一滴25 分钟前
游戏引擎原理与实践 02:揭开3A游戏背后的技术面纱
开发语言·计算机网络·程序人生·游戏·游戏引擎
m0_3807438733 分钟前
Qt实现调用相机进行拍照并进行图像处理
开发语言·c++
ljt272496066133 分钟前
Vue笔记(九)--defineEmits
javascript·vue.js·笔记
wangqiaowq41 分钟前
AST 安全求值
java·开发语言
我们从未走散1 小时前
AI 生图平台如何避免资损:用“扣款与凭据同事务”构建三态账本
开发语言·数据库·php