简体   繁体   English

如何在 Ant 设计中编辑进度条的百分比?

[英]How can I edit the percent of progress bar in Ant design?

I am now using react js and importing the ant design progress component(see https://ant.design/components/progress/ ) But I fail to edit the percentage of the bar with javascript after it is displayed.我现在正在使用react js并导入ant设计进度组件(参见https://ant.design/components/progress/ )但是我无法在显示后用javascript编辑栏的百分比。 I initiate it will this Html code.我将启动此 Html 代码。

<Progress id="progressBar" 

strokeColor={{from: '#108ee9', to: '#87d068'}}

percent={0}

status="active"/>

I tried to call progressBar.percent to edit but it does not work.我试图调用progressBar.percent进行编辑,但它不起作用。

Just store your pecentage in useState只需将您的百分比存储在useState

const [percent, setPercent] = useState(0)

and pass it to Progress:并将其传递给 Progress:

<Progress id="progressBar" 
strokeColor={{from: '#108ee9', to: '#87d068'}}
percent={percent}
status="active"/>

and then simply call setPercent(50) to change your state.然后只需调用setPercent(50)即可更改您的 state。

This is fundamental principe how to work with states in react.这是如何在 React 中与状态一起工作的基本原则。 You can read more here你可以在这里阅读更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM