uniapp实现进度条组件

在这里插入图片描述

  1. 首先,在uniapp项目中创建一个自定义组件,可以命名为Progress.vue。
  2. 在Progress.vue中,编写如下代码:
<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:
<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>

相关推荐

  1. uniapp步骤 组件

    2024-03-10 01:08:03       14 阅读
  2. Python实现进度

    2024-03-10 01:08:03       41 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-10 01:08:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-10 01:08:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-10 01:08:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-10 01:08:03       20 阅读

热门阅读

  1. leetcode热题100刷题计划

    2024-03-10 01:08:03       19 阅读
  2. 在 Windows 右键菜单添加 Git Bash

    2024-03-10 01:08:03       24 阅读
  3. 如何快速解决leetcode 热题100

    2024-03-10 01:08:03       24 阅读
  4. 利用chatgpt写论文使用教程

    2024-03-10 01:08:03       25 阅读
  5. MySQL学习Day26——事务基础知识

    2024-03-10 01:08:03       24 阅读
  6. 23 easy 226. 翻转二叉树

    2024-03-10 01:08:03       24 阅读