Web开发

代码规范

2018-04-04  本文已影响4人  nimw
  1. React组件中如果添加了监听横竖屏切换的回调函数,则在该组件的willUnmount的时候需要卸载此监听回调。
 componentDidMount(){
        if(DeviceInfo.isIOS()) {
            window.addEventListener('orientationchange',  this._onOrientationChange);
        }
    }
    componentWillUnmount(){
        if(DeviceInfo.isIOS()) {
            window.removeEventListener('orientationchange',  this._onOrientationChange);
        }
    }
上一篇 下一篇

猜你喜欢

热点阅读