判断ios还是android的公共方法

1:在common文件下index.js中写入方法并导出

export var isMobile = {
  Android: function () {
    return !!navigator.userAgent.match(/Android/i);
  },
  iOS: function () {
    return !!navigator.userAgent.match(/iPhone|iPad|iPod/i);
  }
}

2:在需要使用的文件下引入

import { isMobile } from '@/common'

3:使用isMobile下的方法

if (isMobile.iOS()) {
 alert('i am ios')
}
if (isMobile.Android()) {
  alert('i am Android')
}

猜你喜欢

转载自www.cnblogs.com/liangpi/p/11836285.html