有多个按钮时点击单个按钮显示加载中
Posted 进阶的哈姆雷特
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了有多个按钮时点击单个按钮显示加载中相关的知识,希望对你有一定的参考价值。
const { Button } = antd; const { PoweroffOutlined } = icons; class App extends React.Component { state = { loadings: [], }; enterLoading = index => { this.setState(({ loadings }) => { const newLoadings = [...loadings]; newLoadings[index] = true; return { loadings: newLoadings, }; }); setTimeout(() => { this.setState(({ loadings }) => { const newLoadings = [...loadings]; newLoadings[index] = false; return { loadings: newLoadings, }; }); }, 6000); }; render() { const { loadings } = this.state; return ( <> <Button type="primary" loading={loadings[0]} onClick={() => this.enterLoading(0)}> Click me! </Button> <Button type="primary" icon={<PoweroffOutlined />} loading={loadings[1]} onClick={() => this.enterLoading(1)} > Click me! </Button> <Button type="primary" icon={<PoweroffOutlined />} loading={loadings[2]} onClick={() => this.enterLoading(2)} /> </> ); } } ReactDOM.render(<App />, mountNode);
https://ant.design/components/button-cn/
以上是关于有多个按钮时点击单个按钮显示加载中的主要内容,如果未能解决你的问题,请参考以下文章