方法一
export const isMobile = (/(iPhone|iPad|iPod|iOS|Android|SymbianOS|Windows Phone|webOS|BlackBerry)/i).test(navigator.userAgent);
方法二
export const isMobile = !(/(Win|Mac|X11|Linux)/i).test(navigator.platform);
方法三
export const isMobile = (/(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|jigs browser|hiptop|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220)/i).test(navigator.userAgent);
方法四
const browser = {
"versions": function () {
const u = navigator.userAgent;
return {
"trident": u.indexOf("Trident") > -1,
"presto": u.indexOf("Presto") > -1,
"webKit": u.indexOf("AppleWebKit") > -1,
"gecko": u.indexOf("Gecko") > -1 && u.indexOf("KHTML") == -1,
"mobile": !!u.match(/AppleWebKit.*Mobile.*/) || !!u.match(/AppleWebKit/) && u.indexOf("QIHU") && u.indexOf("Chrome") < 0,
"ios": !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
"android": u.indexOf("Android") > -1 || u.indexOf("Linux") > -1,
"iPhone": u.indexOf("iPhone") > -1 || u.indexOf("Mac") > -1,
"iPad": u.indexOf("iPad") > -1,
"webApp": u.indexOf("Safari") == -1,
"ua": u
};
}(),
"language": (navigator.browserLanguage || navigator.language).toLowerCase()
}
export const isMobile = (browser.versions.mobile || browser.versions.ios || browser.versions.android || browser.versions.iPhone || browser.versions.iPad);