util.js中的一些方法__浏览器参数、判断入口、图片处理

1.判断支付宝、微信或其他浏览器
const ua = window.navigator.userAgent;
if (/MicroMessenger/.test(ua)) {
return ‘wx’;
} else if (/Alipay/.test(ua)) {
return ‘ali’;
} else {
return ‘other’
}
if (/iphone|ipad|ipod/i.test(ua)) {
return ‘ios’;
} else if (/android/i.test(ua)) {
return ‘android’;
}

2.获取浏览器参数
function getUrlQuery(param){
const query = window.location.search.substring(1);
var paramArr = query.split(’&’);
for(var i = 0;i < paramArr.length; i++){
const s = paramArr[i].split(’=’);
if (s[0] == param) {
return s[1]
}
}
return ‘’;
}

3.图片处理
function getImgSize(imgPerfix,dpr){ //图片前缀 设备像素比
const All_Images = require.context(’@/assets/img’, true, /\w[[email protected]]?.png/).keys().map(fileName => fileName.split(’/’).pop());
let imgName = ${imgPerfix}@2x.png;
if (dpr=== 3 && All_Images.includes(${imgPerfix}@3x.png)){
imgName = ${imgPerfix}@3x.png
}
return require(~/img/${imgName})
}

import {mapState} from ‘vuex’
computed:{
…mapState(‘homeModule’,[‘dpr’])
}

store/index.js
util.js中的一些方法__浏览器参数、判断入口、图片处理
store/homeModule.js
util.js中的一些方法__浏览器参数、判断入口、图片处理