ebike-plus-ui/src/hooks/useDevicesSize.ts
2025-05-18 12:22:07 +08:00

22 lines
741 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.

import { computed } from "vue";
import { useWindowSize } from "@vueuse/core";
interface DeviceSize {
isPc: ComputedRef<boolean>;
isPad: ComputedRef<boolean>;
isMobile: ComputedRef<boolean>;
}
/**
* 小于 768px适配移动设备如手机
* 768px - 1024px适配平板设备。
* 大于 1024px适配桌面设备。
* @returns PC窗口isPc, 平板窗口isPad, 移动端窗口isMobile
*/
export const useDevicesSize = (): DeviceSize => {
const { width } = useWindowSize();
const isPc = computed(() => width.value > 1024);
const isPad = computed(() => width.value > 768 && width.value <= 1024);
const isMobile = computed(() => width.value <= 768);
return { isPc, isPad, isMobile };
};