我是vuejs的新手。有人帮我吗?如果我单击浏览器刷新按钮,我需要显示弹出窗口。所以我在这里使用了下面的代码。
I am using the code like,
window.onbeforeunload=function(){
return "Your work will be lost.";
}我在一个页面中的beforeMount()生命周期实例下使用了这个函数。但是,当我点击浏览器刷新按钮时,这个弹出窗口显示了多个页面。我想在单个页面中显示此弹出窗口。有谁可以帮我??
发布于 2019-09-16 13:01:39
我知道这是一篇老文章,但也许这篇文章会对你或其他人有所帮助。如上所述,查看实际的代码实现会有很大帮助,但这可能会有所帮助。
<script>
export default {
data: () => ({
shouldPrevent: false
}),
beforeMount() {
window.addEventListener("beforeunload", this.preventNav)
},
beforeDestroy() {
// Don't forget to clean up event listeners
window.removeEventListener("beforeunload", this.preventNav)
},
methods: {
preventNav(e) {
if (!this.shouldPrevent) return
e.preventDefault()
e.returnValue = ""
},
},
}
</script>https://stackoverflow.com/questions/52205402
复制相似问题