javascript - 在组件卸载 Reactjs 之前更改 css 和状态
问题描述
我是新手,我需要在卸载组件之前更改 CSS 类,但是我的组件在卸载之前收到新的道具,并且 css 效果没有出现任何解决方案。提前致谢
getNext=()=>{
this.setState({
isCardFadeOut: true
})
this.secondCard.current.classList.remove('second-card')
this.secondCard.current.classList.add('main-card')
this.thirdCard.current.classList.remove('third-card')
this.thirdCard.current.classList.add('second-card')
this.props.parent.getNext()
}
解决方案
我使用 onTransitionEnd 事件监听器来调用
this.props.parent.getNext()
在 getNext() 上,我进行了 css 更改,其中包括转换,并使函数调用同步如下:
<div ref={this.thirdCard}
onTransitionEnd={this.handleGetNext}
className="content-card third-card"/>
handleGetNext = () => {
this.props.parent.getNext()
}
getNext = () => {
this.firstCard.current.classList.add('card-fading')
this.secondCard.current.classList.remove('second-card')
this.secondCard.current.classList.add('main-card')
this.thirdCard.current.classList.remove('third-card')
this.thirdCard.current.classList.add('second-card')
}
推荐阅读
- android - Color.Transparent 仅在三星设备上为黑色
- angular - 如何在 rxjs 6 中将 switchMap-operators 与函数体链接起来
- sql - 如何联合数据透视列中的多行
- python - 语音识别语音到文本在 python 中不起作用
- c# - 为什么 Type.Equals() 对于泛型类型总是返回 false?
- c++ - 无法让球从屏幕边缘反弹
- r - R:在 .Rprofile 中创建环境
- hyperledger-fabric - 创建 Fabric 网络时如何在我的 Fabric 证书中配置 L、ST、C... 属性?
- python - Python:选择具有更改值的行
- javascript - 使用 JavaScript 的变量中的 TagName 值