App.vue中
export default {
name: 'App',
methods: {
// 判断移动端还是pc端
<!--_isMobile方法-->
_isMobile(){
let flag = navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i)
return flag;
}
},
mounted: function() {
if (this._isMobile()) {
alert('手机端');
<!--移动端首页路由-->
this.$router.replace('/homeAndroid');
}else {
alert('pc端');
<!--pc端首页路由-->
this.$router.replace('/Home');
}
},
}
复制代码
在此之前为解决适配问题“普遍”会给html根节点设置font-size作为根字体计算单位值,适兼容多端配问题。开发者需要实时换算单位、还需要精确到六七位小数点。这样的解决方案在现在看来似乎不是最简洁高
- 5706
- 56
- 6