SDUOJ / sduoj-web2

6 stars 5 forks source link

markdown 编辑器内容有意外丢失的风险 #32

Open yhf2000 opened 1 year ago

yhf2000 commented 1 year ago
  1. 本地记录历史信息
  2. 阻止页面退出
    componentWillMount () {
    // 拦截判断是否离开当前页面
    window.addEventListener('beforeunload', this.beforeunload);
    }
    componentWillUnmount () {
    // 销毁拦截判断是否离开当前页面
    window.removeEventListener('beforeunload', this.beforeunload);
    }
    beforeunload (e) {
    let confirmationMessage = '你确定离开此页面吗?';
    (e || window.event).returnValue = confirmationMessage;
    return confirmationMessage;
    }