简单实现进度条效果(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>
相关推荐
卡比巴拉—林5 分钟前
Python print()函数详讲
开发语言·python
黄团团9 分钟前
Vue2整合Electron开发桌面级应用以及打包发布(提供Gitee源码)
前端·javascript·vue.js·elementui·electron
奶思图米球13 分钟前
Python多环境管理
开发语言·python
JienDa17 分钟前
JienDa聊PHP:基于协同架构的PHP主流框架优势整合与劣势补救策略
开发语言·架构·php
i***395820 分钟前
JAVA系统中Spring Boot 应用程序的配置文件:application.yml
java·开发语言·spring boot
时光追逐者29 分钟前
C# 中 ?、??、??=、?: 、?. 、?[] 各种问号的用法和说明
开发语言·c#·.net·.net core
量化Mike31 分钟前
【python报错】解决卸载Python时报错问题:No Python installation was detected
开发语言·python
q***017734 分钟前
PHP进阶-在Ubuntu上搭建LAMP环境教程
开发语言·ubuntu·php
q***017737 分钟前
Java进阶学习之路
java·开发语言·学习
Zx6236542 分钟前
13.泛型编程 STL技术
java·开发语言·c++