Skip to content

Progress 进度条

介绍

展示操作或任务的当前进度。

基础用法

html
<template>
  <nut-progress percentage="30"></nut-progress>
</template>

设置高度和颜色

html
<template>
  <nut-progress
    percentage="30"
    stroke-width="20"
    stroke-color="rgba(250, 44, 25, 0.47)"
    text-color="red"
  ></nut-progress>
</template>

设置百分比不显示

html
<template>
  <nut-progress percentage="50" :show-text="false"></nut-progress>
</template>

设置百分比内显

html
<template>
  <nut-progress percentage="60" text-inside></nut-progress>
</template>

设置百分比内显自定义内容

html
<template>
  <nut-progress percentage="60" text-inside>
    <image src="https://xxx.xx"></image>
  </nut-progress>
</template>

设置自定义尺寸

内置 small、base、large 三种规格供使用。

html
<template>
  <nut-progress percentage="30" size="small"></nut-progress>
  <nut-progress percentage="50" size="base"></nut-progress>
  <nut-progress percentage="70" size="large"></nut-progress>
</template>

设置状态显示

html
<template>
  <nut-progress
    percentage="30"
    status="active"
    stroke-color="linear-gradient(270deg, rgb(18, 126, 255) 0%, rgb(32, 147, 255) 32%, rgb(13, 242, 204) 100%)"
  ></nut-progress>

  <nut-progress percentage="50" status="icon"></nut-progress>

  <nut-progress
    percentage="100"
    status="icon"
    stroke-width="15"
    stroke-color="linear-gradient(90deg, rgb(180, 236, 81) 0%, rgb(66, 147, 33) 100%)"
  >
    <template #iconName>
      <nut-icon
        name="issue"
        width="15px"
        height="15px"
        color="red"
      ></nut-icon>
    </template>
  </nut-progress>
</template>

动态改变

html
<template>
  <nut-progress :percentage="percentage"></nut-progress>

  <nut-button @click="decrease()">减少</nut-button>
  <nut-button @click="increase()">增加</nut-button>
</template>
ts
const percentage = ref(0);

function decrease() {
  if (percentage.value <= 0) {
    return;
  }

  percentage.value = Math.max(0, percentage.value - 10);
}

function increase() {
  if (percentage.value >= 100) {
    return;
  }

  percentage.value = Math.min(100, percentage.value + 10);
}

API

Props

参数说明类型可选值默认值
percentage百分比number / string-0
is-show-percentage是否需要展示百分号boolean-true
stroke-color进度条背景色string-#f30
stroke-width进度条宽度number / string--
size进度条及文字尺寸stringsmall / base / largebase
show-text是否显示进度条文字内容boolean-true
text-inside进度条文字是否内显boolean-false
text-color进度条文字颜色设置string-#333
text-background进度条文字背景颜色设置string--
status进度条当前状态stringtext / active / icontext

Slots

名称说明
iconName右侧图标

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件

名称默认值
--nut-progress-inner-background-colorlinear-gradient(135deg,var(--nut-primary-color) 0%,var(--nut-primary-color-end) 100%)
--nut-progress-insidetext-backgroundvar(--nut-progress-inner-background-color)
--nut-progress-outer-background-color#f3f3f3
--nut-progress-outer-border-radius12px
--nut-progress-insidetext-border-radius5px
--nut-progress-insidetext-padding3px 5px 3px 6px
--nut-progress-small-height5px
--nut-progress-small-text-font-size7px
--nut-progress-small-text-line-height10px
--nut-progress-small-text-padding2px 4px
--nut-progress-base-height10px
--nut-progress-base-text-font-size9px
--nut-progress-base-text-line-height13px
--nut-progress-base-text-paddingvar(--nut-progress-insidetext-padding)
--nut-progress-large-height15px
--nut-progress-large-text-font-size13px
--nut-progress-large-text-line-height18px
--nut-progress-large-text-paddingvar(--nut-progress-insidetext-padding)

MIT Licensed