PC端和移动端兼容方案
# PC端和移动端兼容方案
通过判断打开设备的类型,区分需要显示的方式和界面
//App.vue
mounted() {
if (this._isMobile()) {
alert("手机端");
// this.$router.replace('/m_index');
} else {
alert("pc端");
// this.$router.replace('/pc_index');
}
},
methods: {
//App.vue
_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;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
上次更新: 10/21/2021, 1:52:09 PM