简单实现进度条效果(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>
相关推荐
言乐61 小时前
Python实现建造微服务商城后台
开发语言·python·算法·微服务·架构
cui_ruicheng1 小时前
Python从入门到实战(六):非序列容器
开发语言·python
月光刺眼1 小时前
用LangChain 打造第一个 Agent:LLM 大脑与 Tool 手脚的完整闭环
javascript·人工智能·全栈
西西学代码1 小时前
Flutter---底部导航栏(2)
开发语言·javascript·flutter
legendary_1631 小时前
SINK芯片:Type-C统一供电时代的小家电核心方案
c语言·开发语言·人工智能·智能手机
momo1 小时前
JAVA基础知识
java·开发语言
凯瑟琳.奥古斯特2 小时前
力扣1013三等分解法与C++实现
开发语言·c++·算法·leetcode·职场和发展
阿奇__2 小时前
uniapp微信小程序图片上传含回显组件(拍照,相册)
前端·javascript·vue.js
xxie1237943 小时前
Python装饰器与语法糖
开发语言·python
郑州光合科技余经理3 小时前
海外外卖平台源码改造实战——多语言核心代码实现
java·开发语言·前端·后端·mysql·架构·php