组件卸载

  • componentWillUnmount()

    在组件被卸载或者销毁的时候执行,方法中不能再有setState的动作。

    一般用作清除组件中起的定义器、webSocket等。

    示例:

    componentWillUnmount() {
      if(this.timer) {
        window.clearInterval(this.timer);
        this.timer = null;
      }
    }
    

    在线示例

results matching ""

    No results matching ""