ebike-plus-ui/src/hooks/useDevicesSize.ts

22 lines
741 B
TypeScript
Raw Normal View History

2025-01-15 20:24:13 +08:00
import { computed } from "vue";
import { useWindowSize } from "@vueuse/core";
2025-05-18 12:22:07 +08:00
interface DeviceSize {
isPc: ComputedRef<boolean>;
isPad: ComputedRef<boolean>;
isMobile: ComputedRef<boolean>;
}
2025-01-15 20:24:13 +08:00
/**
* 768px
* 768px - 1024px
* 1024px
* @returns PC窗口isPc, isPad, isMobile
*/
2025-05-18 12:22:07 +08:00
export const useDevicesSize = (): DeviceSize => {
2025-01-15 20:24:13 +08:00
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 };
};