2
比方說,我有使用Andrew Farmer's example image component當每個個體圖像加載檢測圖像的數目不詳:同步多個圖像的onLoad與之反應
import React from 'react';
class ImageWithStatusText extends React.Component {
constructor(props) {
super(props);
this.state = { imageStatus: null };
}
handleImageLoaded() {
this.setState({ imageStatus: 'loaded' });
}
handleImageErrored() {
this.setState({ imageStatus: 'failed to load' });
}
render() {
return (
<div>
<img
src={this.props.imageUrl}
onLoad={this.handleImageLoaded.bind(this)}
onError={this.handleImageErrored.bind(this)}
/>
{this.state.imageStatus}
</div>
);
}
}
export default ImageWithStatusText;
使用諸如焊劑或終極版的框架,有什麼最簡單的方法來同步所有圖像組件,以檢測何時加載完所有圖像?