Skip to content

progress ​

进度条。

属性说明

属性名类型默认值说明平台差异说明
percentNumber无百分比0~100
show-infoBooleanfalse在进度条右侧显示百分比
border-radiusNumber/String0圆角大小微信基础库2.3.1+、快手小程序
font-sizeNumber/String16右侧百分比字体大小微信基础库2.3.1+
stroke-widthNumber6进度条线的宽度,单位px
activeColorColor#09BB07(百度为#E6E6E6)已选择的进度条的颜色
backgroundColorColor#EBEBEB未选择的进度条的颜色
activeBooleanfalse进度条从左往右的动画
active-modeStringbackwardsbackwards: 动画从头播;forwards:动画从上次结束点接着播App、H5、微信小程序、快手小程序
durationNumber30进度增加1%所需毫秒数微信基础库2.8.2+、H5、快手小程序
@activeendEventHandle动画完成事件微信小程序

示例 查看演示

以下示例代码,来自于hello uni-app项目,推荐使用HBuilderX,新建uni-app项目,选择hello uni-app模板,可直接体验完整示例。

:::preview https://hellouniapp.dcloud.net.cn/pages/component/progress/progress

vue
<template>
  <view>
    <view class="uni-padding-wrap uni-common-mt">
      <view class="progress-box">
        <progress :percent="pgList[0]" show-info stroke-width="3" />
      </view>
      <view class="progress-box">
        <progress :percent="pgList[1]" stroke-width="3" />
        <uni-icons type="close" class="progress-cancel" color="#dd524d"></uni-icons>
      </view>
      <view class="progress-box">
        <progress :percent="pgList[2]" stroke-width="3" />
      </view>
      <view class="progress-box">
        <progress :percent="pgList[3]" activeColor="#10AEFF" stroke-width="3" />
      </view>
      <view class="progress-control">
        <button type="primary" @click="setProgress">设置进度</button>
        <button type="warn" @click="clearProgress">清除进度</button>
      </view>
    </view>
  </view>
</template>
<template>
  <view>
    <view class="uni-padding-wrap uni-common-mt">
      <view class="progress-box">
        <progress :percent="pgList[0]" show-info stroke-width="3" />
      </view>
      <view class="progress-box">
        <progress :percent="pgList[1]" stroke-width="3" />
        <uni-icons type="close" class="progress-cancel" color="#dd524d"></uni-icons>
      </view>
      <view class="progress-box">
        <progress :percent="pgList[2]" stroke-width="3" />
      </view>
      <view class="progress-box">
        <progress :percent="pgList[3]" activeColor="#10AEFF" stroke-width="3" />
      </view>
      <view class="progress-control">
        <button type="primary" @click="setProgress">设置进度</button>
        <button type="warn" @click="clearProgress">清除进度</button>
      </view>
    </view>
  </view>
</template>
js
<script>
export default {
    data() {
      return {
        pgList: [0, 0, 0, 0],
      }
    },
    methods: {
      setProgress() {
        this.pgList = [20, 40, 60, 80];
      },
      clearProgress() {
        this.pgList = [0, 0, 0, 0];
      },
    },
  };
</script>
<script>
export default {
    data() {
      return {
        pgList: [0, 0, 0, 0],
      }
    },
    methods: {
      setProgress() {
        this.pgList = [20, 40, 60, 80];
      },
      clearProgress() {
        this.pgList = [0, 0, 0, 0];
      },
    },
  };
</script>
css
<style>
  .progress-box {
    display: flex;
    height: 50rpx;
    margin-bottom: 60rpx;
  }

  .uni-icon {
    line-height: 1.5;
  }

  .progress-cancel {
    margin-left: 40rpx;
  }

  .progress-control button {
    margin-top: 20rpx;
  }
</style>
<style>
  .progress-box {
    display: flex;
    height: 50rpx;
    margin-bottom: 60rpx;
  }

  .uni-icon {
    line-height: 1.5;
  }

  .progress-cancel {
    margin-left: 40rpx;
  }

  .progress-control button {
    margin-top: 20rpx;
  }
</style>