From 46df470bbba226da5224d9adc1c47ecfadf11e1d Mon Sep 17 00:00:00 2001 From: wujingjing <gersonwu@qq.com> Date: 星期四, 18 七月 2024 14:21:01 +0800 Subject: [PATCH] chart resize --- src/directive/customDirective.ts | 48 +++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/directive/customDirective.ts b/src/directive/customDirective.ts index 83738b5..5a13bdd 100644 --- a/src/directive/customDirective.ts +++ b/src/directive/customDirective.ts @@ -53,13 +53,13 @@ }); } -export const eleFocusDirective =(app:App)=>{ - app.directive('elInputFocus',{ - mounted:(el)=>{ - el.querySelector('input.el-input__inner')?.focus() - } - }) -} +export const eleFocusDirective = (app: App) => { + app.directive('elInputFocus', { + mounted: (el) => { + el.querySelector('input.el-input__inner')?.focus(); + }, + }); +}; /** * 鑷畾涔夋嫋鍔ㄦ寚浠� @@ -184,3 +184,37 @@ }, }); } + +//#region ====================== v-resize ====================== +const resizeMap = new WeakMap(); +const ob = new ResizeObserver((entries) => { + for (const entry of entries) { + // 鑾峰彇dom鍏冪礌鐨勫洖璋� + const handler = resizeMap.get(entry.target); + //瀛樺湪鍥炶皟鍑芥暟 + if (handler) { + // 灏嗙洃鍚殑鍊肩粰鍥炶皟鍑芥暟 + handler({ + width: entry.borderBoxSize[0].inlineSize, + height: entry.borderBoxSize[0].blockSize, + }); + } + } +}); + +export const elementResizeDirective = (app: App) => { + app.directive('resize', { + mounted(el: any, binding: any) { + //灏哾om涓庡洖璋冪殑鍏崇郴濉炲叆map + resizeMap.set(el, binding.value); + //鐩戝惉el鍏冪礌鐨勫彉鍖� + ob.observe(el); + }, + unmounted(el: any) { + //鍙栨秷鐩戝惉 + ob.unobserve(el); + }, + }); +}; + +//#endregion -- Gitblit v1.9.3