简单实现进度条效果(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>
相关推荐
Larry_Yanan8 分钟前
Qt多进程(六)共享内存和信号量
开发语言·qt
BD_Marathon9 分钟前
bean基础配置
java·开发语言
东方忘忧11 分钟前
Qt使用QDesktopServices::openUrl打开系统默认应用(如浏览器,文件,文件夹和邮件)
开发语言·qt
计算机内卷的N天12 分钟前
qt的模态和非模态状态
开发语言·qt
释怀不想释怀1 小时前
Ajax,vue生命周期(自动加载页面发出请求)Axios
前端·javascript·ajax
cz追天之路7 小时前
华为机考--- 字符串最后一个单词的长度
javascript·css·华为·less
半桶水专家7 小时前
go语言中的结构体嵌入详解
开发语言·后端·golang
Light607 小时前
CSS逻辑革命:原生if()函数如何重塑我们的样式编写思维
前端·css·响应式设计·组件化开发·css if函数·声明式ui·现代css
在屏幕前出油8 小时前
二、Python面向对象编程基础——理解self
开发语言·python
阿方索9 小时前
python文件与数据格式化
开发语言·python