ant-design-vue/components/_util/hooks/useBreakpoint.ts

22 lines
492 B
TypeScript
Raw Normal View History

import { onMounted, onUnmounted, Ref, ref } from 'vue';
import ResponsiveObserve, { ScreenMap } from '../../_util/responsiveObserve';
function useBreakpoint(): Ref<ScreenMap> {
const screens = ref<ScreenMap>({});
let token = null;
onMounted(() => {
token = ResponsiveObserve.subscribe(supportScreens => {
screens.value = supportScreens;
});
});
onUnmounted(() => {
ResponsiveObserve.unsubscribe(token);
});
return screens;
}
export default useBreakpoint;