windows/composables/useBreakpoint.ts

29 lines
580 B
TypeScript
Raw Normal View History

2025-09-23 16:43:57 +00:00
import { ref, onMounted, onUnmounted } from 'vue';
const MOBILE_BREAKPOINT = 500;
export function useBreakpoint() {
const isMobile = ref(false);
const update = () => {
if (typeof window !== 'undefined') {
isMobile.value = window.innerWidth < MOBILE_BREAKPOINT;
}
};
onMounted(() => {
update();
2025-09-25 05:38:59 +00:00
if (typeof window !== 'undefined') {
window.addEventListener('resize', update);
}
2025-09-23 16:43:57 +00:00
});
onUnmounted(() => {
if (typeof window !== 'undefined') {
window.removeEventListener('resize', update);
}
});
return { isMobile };
}