vue判断设备

以下代码直接写在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;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值