mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-27 15:41:32 +08:00
chore: bump 2.0.0-rc.3
This commit is contained in:
@@ -4,7 +4,6 @@ import { tryOnMounted, tryOnUnmounted } from '/@/utils/helper/vueHelper';
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { useDebounce } from '/@/hooks/core/useDebounce';
|
||||
import { CancelFn } from '../core/types';
|
||||
|
||||
interface WindowSizeOptions {
|
||||
once?: boolean;
|
||||
@@ -12,25 +11,33 @@ interface WindowSizeOptions {
|
||||
listenerOptions?: AddEventListenerOptions | boolean;
|
||||
}
|
||||
|
||||
export function useWindowSizeFn<T>(fn: Fn<T>, wait = 150, options?: WindowSizeOptions): CancelFn {
|
||||
export function useWindowSizeFn<T>(fn: Fn<T>, wait = 150, options?: WindowSizeOptions) {
|
||||
let handler = () => {
|
||||
fn();
|
||||
};
|
||||
const [handleSize, cancel] = useDebounce(handler, wait, options);
|
||||
handler = handleSize;
|
||||
|
||||
tryOnMounted(() => {
|
||||
const start = () => {
|
||||
if (options && options.immediate) {
|
||||
handler();
|
||||
}
|
||||
window.addEventListener('resize', handler);
|
||||
};
|
||||
|
||||
const stop = () => {
|
||||
window.removeEventListener('resize', handler);
|
||||
cancel();
|
||||
};
|
||||
|
||||
tryOnMounted(() => {
|
||||
start();
|
||||
});
|
||||
|
||||
tryOnUnmounted(() => {
|
||||
window.removeEventListener('resize', handler);
|
||||
cancel();
|
||||
stop();
|
||||
});
|
||||
return cancel;
|
||||
return [start, stop];
|
||||
}
|
||||
|
||||
export const useWindowSize = (wait = 150, options?: WindowSizeOptions) => {
|
||||
|
Reference in New Issue
Block a user