初始化
This commit is contained in:
18
mokee-gateway-web/src/composables/useIsMobile.ts
Normal file
18
mokee-gateway-web/src/composables/useIsMobile.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* 响应式检测是否为手机屏幕(宽度 <= 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
|
||||
}
|
||||
Reference in New Issue
Block a user