[英]The onLoad event is never triggered
我試圖弄清楚為什么onload事件永遠不會被調用。 一切構建都沒有錯誤,類似的onLoad事件在不同的組件中運行。 導出類工作擴展了React.Component {
constructor(props) {
super(props);
this.state = {
allImgLoaded: false,
boxHovered: false,
projects: projects
}
this.handleWorkLoad = this.handleWorkLoad.bind(this);
}
componentWillMount() {
window.scrollTo(0,0);
}
handleWorkLoad() {
console.log("called");
this.setState({
allImgLoaded: true
})
}
render() {
return (
<div className={this.state.allImgLoaded ? "work" : "work invisible"} onLoad={this.handleWorkLoad}>
</div>
);
}
};
export default Work;
在react中,您具有componentDidMount方法,該方法使您能夠在組件完成其加載階段后運行特定代碼:
class Work extends React.Component {
constructor(props) {
super(props);
this.state = {
allImgLoaded: false,
boxHovered: false,
projects: projects
}
this.handleWorkLoad = this.handleWorkLoad.bind(this);
}
componentWillMount() {
window.scrollTo(0,0);
}
componentDidMount() {
this.handleWorkLoad()
}
handleWorkLoad() {
console.log("called");
this.setState({
allImgLoaded: true
})
}
render() {
return (
<div className={this.state.allImgLoaded ? "work" : "work invisible"}>
</div>
);
}
};
export default Work;
react中的div
元素沒有onLoad
事件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.