mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-09-17 09:26:20 +00:00
21 lines
497 B
TypeScript
21 lines
497 B
TypeScript
import { onBeforeUnmount, reactive } from 'vue';
|
|
|
|
export const useWindowRect = () => {
|
|
const rect = reactive({ width: globalThis.innerWidth, height: globalThis.innerHeight });
|
|
|
|
const windowResizeHandler = () => {
|
|
rect.width = globalThis.innerWidth;
|
|
rect.height = globalThis.innerHeight;
|
|
};
|
|
|
|
globalThis.addEventListener('resize', windowResizeHandler);
|
|
|
|
onBeforeUnmount(() => {
|
|
globalThis.removeEventListener('resize', windowResizeHandler);
|
|
});
|
|
|
|
return {
|
|
rect,
|
|
};
|
|
};
|