Vue检测web端和移动端,并强制手机横屏
mounted() {if (navigator.userAgent.match(/(iPhone|Android|iPad)/i)) {let width = document.documentElement.clientWidth;let height = document.documentElement.clientHeight;if (width < height) {alert("
·
mounted() {
if (navigator.userAgent.match(/(iPhone|Android|iPad)/i)) {
let width = document.documentElement.clientWidth;
let height = document.documentElement.clientHeight;
if (width < height) {
alert("手机屏幕横过来嗷");
this.loading = true;
document.getElementById("loading").style.zIndex = 2021;
window.addEventListener("resize", this.renderResize);
}
}
},
beforeUnmount() {
window.removeEventListener("resize", this.renderResize);
},
methods: {
renderResize() {
let width = document.documentElement.clientWidth;
let height = document.documentElement.clientHeight;
if (width > height) {
this.loading = false;
document.getElementById("loading").style.zIndex = -5;
} else {
this.loading = true;
document.getElementById("loading").style.zIndex = 2021;
}
},
},
更多推荐
已为社区贡献3条内容
所有评论(0)