简单实现进度条效果(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>
相关推荐
应用市场38 分钟前
Qt QTreeView深度解析:从原理到实战应用
开发语言·数据库·qt
ooooooctober1 小时前
PHP代码审计框架性思维的建立
android·开发语言·php
864记忆1 小时前
Qt Widgets 模块中的函数详解
开发语言·qt
white-persist1 小时前
差异功能定位解析:C语言与C++(区别在哪里?)
java·c语言·开发语言·网络·c++·安全·信息可视化
q***72871 小时前
Golang 构建学习
开发语言·学习·golang
hmbbcsm1 小时前
练习python题目小记(五)
开发语言·python
kokunka1 小时前
C#类修饰符功能与范围详解
java·开发语言·c#
仟濹2 小时前
【Java 基础】3 面向对象 - this
java·开发语言·python
Dxy12393102162 小时前
Python一个类的特殊方法有哪些
开发语言·python
爱吃烤鸡翅的酸菜鱼2 小时前
如何用【rust】做一个命令行版的电子辞典
开发语言·rust