vue判断手机类型是安卓、微信或IOS

点击按钮

<div class="click" @click="clickApp">点击触发</div>

methods:{
   downApp() {
        let ua = navigator.userAgent.toLowerCase();
        //Android终端
        let isAndroid = ua.indexOf('Android') > -1 || ua.indexOf('Adr') > -1;  
·     //Ios终端
        let isiOS = !!ua.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); 
        if (isWeixinBrowser()) {
           this.$router.push({
              path: '/product'
           })
        } else {
           if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
              //Ios
           } else if (/(Android)/i.test(navigator.userAgent)) {
              //Android终端
              window.location = 'http://www.xyfan.top/app.apk'
           }
        }

        function isWeixinBrowser() {
            return (/micromessenger/.test(ua)) ? true : false;
        }
  }
}

猜你喜欢

转载自blog.csdn.net/gqzydh/article/details/82415194