“SideBar”组件在页面加载时按预期切换,但是...我不知道如何在加载另一个页面时将其切换回。我是 React 的新手,任何帮助将不胜感激。 提前致谢。
constructor(props) {
super(props);
this.state = {
headlines:[],
isLoaded: false,
error:null
}
}
componentDidMount(){
this.toggleSideBar();
}
componentWillUnmount(){
this.toggleSideBar();
}
toggleSideBar = event => {
this.sidebar.toggle()
}
render() {
return (
<div>
<Row className="d-none d-md-block">
<SideBar style={{ backgroundColor: 'rgba(0, 0, 0, 0.800)'}}
ref={(sidebar => this.sidebar = sidebar)}>
<div style={{marginTop: "16vh"}}><TFGuage/></div>
<div style={{marginTop: "0vh"}}><GBGuage/></div>
</SideBar>
</Row>
</div>
);
}
}