简单实现进度条效果(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>
相关推荐
yvvvy2 分钟前
一文搞懂 position:从小红点到粘性导航,再到浏览器底层原理
前端·javascript
胡gh13 分钟前
中断渲染,利用fiber解决性能问题,性能优化又有的说了
前端·javascript·面试
AliciaIr15 分钟前
前端面试:红绿灯问题与异步编程的底层实践
前端·javascript
已读不回14317 分钟前
移动端视口终极解决方案:使用 Visual Viewport封装一个优雅的 React Hook
前端·javascript·react.js
洋流18 分钟前
0基础进大厂,第13天:Promise:你先等等我
前端·javascript·面试
luckyCover20 分钟前
我不允许你还不了解this、call、apply、bind
前端·javascript
用户479492835691523 分钟前
你知道using 和 await using这两个js新特性吗?
前端·javascript
胡gh23 分钟前
深入理解底层let,var,const;面试官:"这是大佬这是大佬"
javascript·后端·面试
Mintopia30 分钟前
🎨 AiGC × Web Markdown:把 AI 的碎碎念渲染成人类能看懂的彩虹
前端·javascript·aigc
Mintopia34 分钟前
🚀 Next 数据库集成:建模篇
前端·javascript·next.js