- 首先,需要引入Antd的Progress组件。
import { Progress } from 'antd';
- 接着,定义一个数组,用于存放堆叠式进度条的每一个小块。
const progressArr = [
{ percent: 30, color: 'red' },
{ percent: 50, color: 'orange' },
{ percent: 20, color: 'green' },
];
- 最后,在页面中使用Progress组件,并通过map方法遍历progressArr数组,将每个小块渲染出来。
注:此处的strokeWidth为进度条的宽度,可以根据需要进行调整。而reduce方法是将数组中每个小块的percent相加,然后取平均值,作为整个堆叠式进度条的进度值显示出来。