判断手机浏览器

301 阅读1分钟

//判断浏览器函数

  let ua = window.navigator.userAgent.toLowerCase();
  let regZFB = /alipay/gi,
    regWX = /MicroMessenger/gi;
  if (Vue.prototype.getData('platform')) {
    return Vue.prototype.getData('platform');
  }
  if (regZFB.test(ua)) {
    Vue.prototype.setData('platform', 'zhifubao');
    return 'zhifubao';
  }
  if (regWX.test(ua)) {
    Vue.prototype.setData('platform', 'weixin');
    return 'weixin';
  }
  Vue.prototype.setData('platform', 'browser');
  return 'browser';
};