简单实现进度条效果(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>
相关推荐
Bigemap5 分钟前
BigemapPro快速添加历史影像(Arcgis卫星地图历史地图)
java·开发语言
给月亮点灯|8 分钟前
Vue3基础知识-setup()、ref()和reactive()
前端·javascript·vue.js
芜青9 分钟前
【Vue2手录12】单文件组件SFC
前端·javascript·vue.js
进击的_鹏17 分钟前
【C++11】initializer_list列表初始化、右值引用和移动语义、可变参数模版等
开发语言·c++
mark-puls24 分钟前
C语言打印爱心
c语言·开发语言·算法
Martin-Luo28 分钟前
Vue3 通过json配置生成查询表单
javascript·vue.js·json
梦想CAD控件29 分钟前
(在线CAD平台)网页集成CAD SDK的方法
前端·javascript·github
掘金约基奇_31 分钟前
JS-SDK开发企微侧边栏
前端·javascript
西阳未落31 分钟前
C语言柔性数组详解与应用
c语言·开发语言·柔性数组
Huhbbjs32 分钟前
SQL 核心概念与实践总结
开发语言·数据库·sql