diff --git a/public/react/src/modules/question/Questionitem_banks.js b/public/react/src/modules/question/Questionitem_banks.js index d07d593a0..0b8f0213e 100644 --- a/public/react/src/modules/question/Questionitem_banks.js +++ b/public/react/src/modules/question/Questionitem_banks.js @@ -1,5 +1,5 @@ import React, {Component} from "react"; -import {Link, NavLink} from 'react-router-dom'; +import {Link, NavLink,Prompt} from 'react-router-dom'; import {WordsBtn, ActionBtn, SnackbarHOC, getImageUrl,queryString} from 'educoder'; import axios from 'axios'; import { @@ -172,6 +172,20 @@ class Questionitem_banks extends Component { } + componentWillMount () { + // 拦截判断是否离开当前页面 + window.addEventListener('beforeunload', this.beforeunload); + } + componentWillUnmount () { + // 销毁拦截判断是否离开当前页面 + window.removeEventListener('beforeunload', this.beforeunload); + } + beforeunload (e) { + let confirmationMessage = '你确定离开此页面吗?'; + (e || window.event).returnValue = confirmationMessage; + return confirmationMessage; + } + getdata = (data) => { // const url=`/item_banks.json`; @@ -510,6 +524,10 @@ class Questionitem_banks extends Component {