feat: right-click menu supports multiple levels

This commit is contained in:
vben
2020-11-01 17:28:38 +08:00
parent c8021ef325
commit f645680a3b
15 changed files with 138 additions and 52 deletions

View File

@@ -3,6 +3,7 @@ import { getCurrentInstance, onBeforeUnmount, ref, Ref, unref } from 'vue';
const domSymbol = Symbol('watermark-dom');
export function useWatermark(appendEl: Ref<HTMLElement | null> = ref(document.body)) {
let func: Fn = () => {};
const id = domSymbol.toString();
const clear = () => {
const domId = document.getElementById(id);
@@ -10,6 +11,7 @@ export function useWatermark(appendEl: Ref<HTMLElement | null> = ref(document.bo
const el = unref(appendEl);
el && el.removeChild(domId);
}
window.addEventListener('resize', func);
};
const createWatermark = (str: string) => {
clear();
@@ -45,7 +47,7 @@ export function useWatermark(appendEl: Ref<HTMLElement | null> = ref(document.bo
function setWatermark(str: string) {
createWatermark(str);
const func = () => {
func = () => {
createWatermark(str);
};
window.addEventListener('resize', func);
@@ -53,7 +55,6 @@ export function useWatermark(appendEl: Ref<HTMLElement | null> = ref(document.bo
if (instance) {
onBeforeUnmount(() => {
clear();
window.addEventListener('resize', func);
});
}
}