feat: 🚀 当页面退出给出是否确认提示

This commit is contained in:
bunny 2024-05-10 16:10:13 +08:00
parent 15278666c3
commit 95a4af2b08
3 changed files with 23 additions and 2 deletions

View File

@ -1,8 +1,9 @@
import { App, Directive } from 'vue'; import { App, Directive } from 'vue';
import copy from './modules/copy'; import copy from './modules/copy';
import existShow from './modules/existShow';
import waterMarker from './modules/waterMarker'; import waterMarker from './modules/waterMarker';
const directivesList: { [key: string]: Directive } = { copy, waterMarker }; const directivesList: { [key: string]: Directive } = { copy, waterMarker, existShow };
/** /**
* *

View File

@ -0,0 +1,20 @@
import { Directive } from 'vue';
interface ElType extends HTMLElement {
copyData: string | number; // 定义一个属性,用于存储需要复制的数据
__handleClick__: any; // 定义一个属性,用于存储事件处理函数
}
/**
* * 退
*/
const existShow: Directive = {
// 指令与元素绑定时触发
beforeMount(el: ElType) {
window.onbeforeunload = function (event) {
(event || window.event).returnValue = '确定离开此页吗?';
};
},
};
export default existShow;

View File

@ -1,5 +1,5 @@
<template> <template>
<div v-waterMarker="{ text: 'Bunny Admin', textColor: 'rgba(180, 180, 180, 0.6)' }"> <div v-waterMarker="{ text: 'Bunny Admin', textColor: 'rgba(180, 180, 180, 0.6)' }" v-existShow>
<h1>bunny/default页面</h1> <h1>bunny/default页面</h1>
<My /> <My />
<RouterView /> <RouterView />