我使用了ReactJS框架,我尝试了一下,这个组件在200ms后将它的样式从opacity 0变成了opacity 1。有可能做这样的setTimeout吗?
<GreetingHeadline styles={?} id={this.props.user.id} />发布于 2019-01-07 04:45:48
您可以将变量设置为GreetingHeadline的父组件的状态:
constructor() {
this.state = {
transparent: true;
}
}然后,您可以在componentDidMount生命周期的方法中使用setTimeout:
componentDidMount() {
this.setTimeout(() => {
this.setState({ transparent: false });
}, 200);
}最后,您可以在GreetingHeadline组件的属性中使用状态变量:
<GreetingHeadline
styles={{ opacity: this.state.transparent ? '0.7' : '1' }}
id={this.props.user.id}
/>https://stackoverflow.com/questions/54065685
复制相似问题