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>
相关推荐
平头哥~3 小时前
Day 07 _ 那条 1px 的线,为什么在手机上忽粗忽细
前端·css·样式·学习资料
小江的记录本4 小时前
【CSS】CSS 动画:transition、animation、transform、CSS3 新特性(附《思维导图》)
前端·css·安全·spring·前端框架·css3·动画
circuitsosk4 小时前
任务规划器的三种范式对比:ReAct、Plan-and-Execute 与 Tree-of-Thought 在真实业务中的取舍
前端·javascript·python·react.js·llm·ai agent
hzxpaipai5 小时前
企业官网技术架构拆解:前端、后台、数据库、服务器如何协同
前端·数据库·架构
深念Y7 小时前
Lenovo XiaoXinAir 14 — 性能模式切换
前端·网络
计算机魔术师8 小时前
Meta突然杀进第一梯队:一个新模型,把AI推理成本打下来8倍
前端
IT_陈寒8 小时前
Redis缓存雪崩把我坑惨了,这次长记性了
前端·人工智能·后端
风骏时光牛马8 小时前
提示词工程:大模型效能挖掘与指令设计实战
前端
仓三8 小时前
Chrome DevTools MCP 上手:让 Coding Agent 自己调试前端页面
前端·chrome devtools·mcp