注意是在生命周期:mounted中:
mounted() {
const userAgent = window.navigator.userAgent;
if (userAgent.indexOf("Android") > -1) {
console.log("客户端类型:Android");
} else if (
userAgent.indexOf("iPhone") > -1 ||
userAgent.indexOf("iPad") > -1 ||
userAgent.indexOf("iPod") > -1
) {
console.log("客户端类型:iOS");
} else if (
userAgent.indexOf("Mac OS X") > -1 ||
userAgent.indexOf("Windows") > -1
) {
console.log("客户端类型:PC");
} else if (userAgent.indexOf("iPad") > -1) {
console.log("客户端类型:iPad");
} else {
console.log("客户端类型:未知");
}
},