代码
utils - checkVersion.js
function checkSystemVersion () {
if(typeof window === 'undefined') return false;
// window环境操作系统区分
let systemInfo = window.navigator.userAgent,
result = {};
/Android/i.test(systemInfo) ? result.isAndroid = true : result.isAndroid = false;
/iphone|ipad/i.test(systemInfo) ? result.isIOS = true : result.isIOS = false;
return result;
}
export default checkSystemVersion
使用
<div v-show='checkVersion.isAndroid'>Android</div>
<div v-show='checkVersion.isIOS'>IOS</div>
<div :class="[{ 'androidClass': checkVersion.isAndroid }, { 'iphoneClass': checkVersion.isIOS }]"></div>
// 样式
.androidClass {}
.iphoneClass {}
import checkSystemVersion from '@/utils/checkVersion'
data() {
return {
checkVersion:null,
}
},
created() {
this.checkVersion = checkSystemVersion();
alert(JSON.stringify(this.checkVersion));
},