uniapp实现进度条组件

  1. 首先,在uniapp项目中创建一个自定义组件,可以命名为Progress.vue。

  2. 在Progress.vue中,编写如下代码:

js 复制代码
<template>
  <view class="progress">
    <view class="progress-bar" :style="{width: progress + '%'}"></view>
  </view>
</template>


export default {
  props: {
    progress: {
      type: Number,
      default: 0
    }
  }
}
</script>

<style>
.progress {
  width: 100%;
  height: 10px;
 background-color: #f0f0f0;
}

.progress-bar {
  height: 100%;
  background-color: #0078d4;
}
</style>
  1. 在需要使用进度条的页面中,引入Progress组件,并传入后端返回的进度值作为props:
js 复制代码
<template>
  <view>
    <Progress :progress="progress"></Progress>
  </view>
</template>

<script>
import Progress from '@/components/Progress.vue'

export default {
  components: {
    Progress
  },
  data() {
    return {
      progress: 8 // 假设后端返回的进度值为8
    }
  }
}
</script>
相关推荐
DianSan_ERP4 小时前
电商架构演进:如何在高并发场景下实现多平台API的标准化履约?
运维·前端·网络·安全·架构·自动化
碎_浪6 小时前
给键盘党的英语记忆工具:我做了一款「打字背单词」桌面应用
前端·程序员·ai编程
阿成学长_Cain7 小时前
Linux dirs命令详解|Bash目录堆栈管理快速切换目录实战教程
linux·运维·前端·数据库
yqcoder8 小时前
httpOnly 是什么,又有什么用?
开发语言·前端·javascript
IT_陈寒8 小时前
Java的Stream.parallel()把我CPU跑爆了,这种优化要谨慎
前端·人工智能·后端
小皮虾8 小时前
小程序首页性能优化实战:从 4 秒到 1.8 秒
前端·微信小程序
山河木马8 小时前
GPU自动处理专题1-裁剪到底在裁什么(裁剪)
前端·webgl·计算机图形学
奔跑的蜗牛ing8 小时前
CentOS Nginx 安装与静态文件服务器配置指南
前端·面试·架构
子兮曰8 小时前
Bun 重写为 Rust:11天、64个Claude、16.5万美元,一次改变行业认知的激进实验
前端·后端·bun