判断设备是移动端还是PC
javascript
isMobile() {
// Regular expression to match common mobile user agent strings
var mobileRegex = /Mobi|Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i;
return mobileRegex.test(navigator.userAgent);
}
判断系统是IOS还是Android
javascript
detectOS() {
this.loading = true;
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
// iOS
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
this.device = "iOS";
}
// Android
else if (userAgent.match(/Android/i)) {
this.device = "Android";
}
// 如果不是上述两者,可能是PC或其他平台,可根据需要添加更多判断
else {
this.device = "Unknown";
}
}