美文网首页
vue-判断设备移动端还是pc端

vue-判断设备移动端还是pc端

作者: _孙小胖 | 来源:发表于2019-08-22 14:03 被阅读0次
App.vue中

export default {
  name: 'App',
  methods: {
    // 判断移动端还是pc端
    <!--_isMobile方法-->
    _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: function() {
    if (this._isMobile()) {
      alert('手机端');
      <!--移动端首页路由-->
      this.$router.replace('/homeAndroid');
    }else {
      alert('pc端');
      <!--pc端首页路由-->
      this.$router.replace('/Home');
    }
  },
}
image
image

相关文章

网友评论

      本文标题:vue-判断设备移动端还是pc端

      本文链接:https://www.haomeiwen.com/subject/hxsnsctx.html