vue-adaptive-hooks
Version:
Provide the best experience for user devices and network restrictions
27 lines (23 loc) • 644 B
JavaScript
let unsupported;
// 检查浏览器是否支持 Navigator.deviceMemory
if (
!!(
typeof window !== "undefined" &&
("ontouchstart" in window ||
(window.DocumentTouch &&
typeof document !== "undefined" &&
document instanceof window.DocumentTouch))
) ||
!!(
typeof navigator !== "undefined" &&
(navigator.maxTouchPoints || navigator.msMaxTouchPoints)
)
) {
unsupported = false;
} else {
unsupported = true;
}
const useTouch = () => {
return !unsupported ? { touch: true } : { unsupported };
};
export { useTouch };