当前位置: 移动技术网 > IT编程>脚本编程>vue.js > Vue项目判断 是移动端还是PC , 微信 , iOS , 安卓

Vue项目判断 是移动端还是PC , 微信 , iOS , 安卓

2020年08月14日  | 移动技术网IT编程  | 我要评论
场景 如果是移动端, 则进入h5页面去download,如果是PC 则进入官网首页方案 methods: { // 判断移动端还是pc端 _isMobile() { let flag = navigator.userAgent.match( /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|Brow

场景 如果是移动端, 则进入h5页面去download,如果是PC 则进入官网首页

方案

在这里插入图片描述

 methods: {
    // 判断移动端还是pc端
    _isMobile() {
      let flag = navigator.userAgent.match(
        /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
      )
      return flag
    }
  },
  mounted() {
    if (this._isMobile()) {
      console.log('isMobile')
      this.$router.push({ name: 'mobile' })
    }
  }

场景 在移动端 点击下载后, 判断 是微信 安卓 iOS

在这里插入图片描述

  downLoad() {
      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.ShowDark = !this.ShowDark
        alert('我是微信')
      } else {
        if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
          //ios
          alert('ios')
          window.location = 'http://www.baidu.com'
        } else if (/(Android)/i.test(navigator.userAgent)) {
          //android
          alert('安卓')
          window.location = 'http://www.taobao.com'
        }
      }

      function isWeixinBrowser() {
        return /micromessenger/.test(ua) ? true : false
      }
    },
参考链接: https://blog.csdn.net/qq_39603448/article/details/87251424

本文地址:https://blog.csdn.net/Ton555555/article/details/107959872

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网