首页 > 其他分享 >关闭、刷新浏览器

关闭、刷新浏览器

时间:2022-11-01 14:14:16浏览次数:45  
标签:浏览器 onUnmounted onMounted onBeforeUnload 关闭 刷新


import { onMounted, onUnmounted, ref } from "vue"; /** 关闭、刷新浏览器 */     function onBeforeUnload (e:Event) {         // 这个文案其实是无效的,无法自定义浏览器提示         const msg = '当前修改的内容未保存,关闭会造成内容丢失,确定继续关闭浏览器么?'         e.preventDefault()         e.returnValue = true         return msg     }        onMounted(() => {     window.addEventListener("beforeunload", onBeforeUnload);     })
    onUnmounted(() => {          window.removeEventListener('beforeunload', onBeforeUnload);     })

标签:浏览器,onUnmounted,onMounted,onBeforeUnload,关闭,刷新
From: https://www.cnblogs.com/ylblogs/p/16847471.html

相关文章