【发布时间】:2021-11-29 19:21:55
【问题描述】:
我有一个文件列表和一个下载每个文件的按钮,我创建了一个状态以在用户单击时禁用按钮并在下载开始时启用它。
这是按钮:
<Button disabled={this.state.disabled} onClick={(e) => { e.stopPropagation(); this.isDownload(props)}} />
这是带有下载功能的代码
import React from 'react';
import autoBind from 'react-autobind';
constructor(props) {
super(props);
autoBind(this);
}
async isDownload(file) {
this.setState({
disabled: true
});
console.log('start the download');
const document = await this.props.getFile(fileId);
if (document.statusCode == 200) {
this.setState({ disabled: false })
};
}
这可行,但是它会禁用所有按钮,我只需要禁用我单击的按钮。我该怎么做?
谢谢!
【问题讨论】:
标签: javascript reactjs binding bind