reactjs - 如何使用fabric UI在进度条中显示进度完成百分比?
问题描述
我正在使用流利的 UI 来显示进度条。
我引用的链接: https ://developer.microsoft.com/en-us/fluentui#/controls/web/progressindicator
我在使用反应显示进度条中的百分比时遇到了困难。有人可以就此提出建议。
谢谢,
解决方案
如果您只想显示百分比数字,那么我所做的就是将百分比添加到<p>
标签并使用用于增加进度条的百分比数字来显示百分比数字。
由于数字从 0 增加到 1 docs
,我们可以做的是将输出乘以100并取其中Math.floor
的一个。
const { ProgressIndicator, Fabric: FabricComponent, initializeIcons } = window.Fabric;
// Initialize icons in case this example uses them
initializeIcons();
const intervalDelay = 100;
const intervalIncrement = 0.01;
const ProgressIndicatorBasicExample: React.FunctionComponent = () => {
const [percentComplete, setPercentComplete] = React.useState(0);
React.useEffect(() => {
const id = setInterval(() => {
setPercentComplete((intervalIncrement + percentComplete) % 1);
}, intervalDelay);
return () => {
clearInterval(id);
};
});
return (
<>
<ProgressIndicator label="Example title" description="Example description"
percentComplete={percentComplete} />
<p>{Math.floor(percentComplete * 100)}%</p>
</>
);
};
const ProgressIndicatorBasicExampleWrapper = () => <FabricComponent><ProgressIndicatorBasicExample /></FabricComponent>;
ReactDOM.render(<ProgressIndicatorBasicExampleWrapper />, document.getElementById('content'))
推荐阅读
- jquery - 使用 Ajax 和 Jquery 显示数据
- docker - Docker exec 打开另一个容器的终端
- java - Spring Boot项目结构冲突
- python - 如何使用 replit db 使用 discord.py 制作排行榜命令
- node.js - 如何在mongodb中将文件引用到对象
- android - 如何将值从一个活动中的片段传递到另一个活动?
- html - 转换 iframe 内容以适应父元素
- python - 如何在 pyomo 模型中提取索引变量信息并构建 Pandas Dataframe
- batch-file - 使用批处理脚本复制早于特定日期范围的目录的文件和文件夹
- dhall - 如何在 dhall 中键入异构列表?