npm地址:https://www.npmjs.com/package/ua-parser-js
1.安装
npm install ua-parser-js
2.引入
import uaParserJs from 'ua-parser-js';
3.使用
const uaParser = uaParserJs();
const { browser, cpu, device, engine, os, ua } = uaParser;
const u = ua.toLowerCase();
/*
{
ua: "",
browser: {
name: "",
version: "",
major: "" //@deprecated
},
engine: {
name: "",
version: ""
},
os: {
name: "",
version: ""
},
device: {
model: "",
type: "",
vendor: ""
},
cpu: {
architecture: ""
}
}
*/
// 包名: 微信内置浏览器 某app
const [isWx, isApp] = ['micromessenger', 'stagemall'].map((item) => u.includes(item));
// 或者
const isHhhApp = u.includes('com.puhui.hhh'); // 某app
export default {
uaParser,
browser,
cpu,
device,
engine,
os,
ua,
u,
isWx,
isApp,
isHhhApp,
};