Files
mokeegateway/mokee-gateway-web/src/composables/useIsMobile.ts
2026-07-15 16:13:27 +08:00

19 lines
472 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 响应式检测是否为手机屏幕(宽度 <= 768px
* 用于桌面表格 / 手机卡片的条件渲染
*/
import { ref, onMounted, onUnmounted } from 'vue'
export function useIsMobile() {
const isMobile = ref(window.innerWidth <= 768)
function check() {
isMobile.value = window.innerWidth <= 768
}
onMounted(() => window.addEventListener('resize', check))
onUnmounted(() => window.removeEventListener('resize', check))
return isMobile
}