页面刷新
。当用户点击刷新图标或按下F5时,我需要找出该事件。我尝试过使用stackoverflow post中的javascript函数。
我使用了javascript函数
beforeunload
,但仍然没有成功。onUnload(event) {
alert('page Refreshed')
}
componentDidMount() {
window.addEventListener("beforeunload", this.onUnload)
}
componentWillUnmount() {
window.removeEventListener("beforeunload", this.onUnload)
}
这里我在stackblitz上有完整的代码。
e.keyCode === 116
,这是 F5 键? 以下是如何实现的示例:https://dev59.com/vV4c5IYBdhLWcg3wgqr2#34634290 - Ralph David Abernathy