以下代码直接写在main.js中为了方便先采用以下写法
在组件中使用时通过this.
i
s
I
O
S
(
)
/
t
h
i
s
.
isIOS()/this.
isIOS()/this.isAndroid()/this.$isWeixin()即可
//判断是否安卓
Vue.prototype.$isAndroid = () => {
return /android/i.test(navigator.userAgent.toLowerCase());
}
//判断是否ios
Vue.prototype.$isIos = () => {
return /(iphone|ipad|ipod|ios)/i.test(navigator.userAgent.toLowerCase()) || (/Mac OS/i.test(navigator.userAgent.toLowerCase()) && !/safari/i.test(navigator.userAgent.toLowerCase()));
}
//判断是否微信
Vue.prototype.$isWeixin = () => {
return /micromessenger/i.test(navigator.userAgent.toLowerCase());
}
//判断是否支付宝
Vue.prototype.$isAli = () => {
return /alipayclient/i.test(navigator.userAgent.toLowerCase());
}
//判断是否钉钉
Vue.prototype.$isDing = () => {
return /(aliapp|dingtalk)/i.test(navigator.userAgent.toLowerCase());
}
//判断是否QQ
Vue.prototype.$isQq = () => {
if(navigator.userAgent.toLowerCase().indexOf(' qq')>-1 && navigator.userAgent.toLowerCase().indexOf('mqqbrowser') <0){
return true;
}else{
return false;
}
}