mounted(){
this.handleScreen()
window.addEventListener("resize",()=>{
this.handleScreen()
})
},
methods:{
handleScreen(){
const m = this.detectZoom();
document.body.style.zoom = 100/Number(m);
},
detectZoom(){
let ratio = 0,
screen = window.screen,
ua = navigator.userAgent.toLowerCase();
if (window.devicePixelRatio !== undefined) {
ratio = window.devicePixelRatio;
} else if (~ua.indexOf('msie')) {
if (screen.deviceXDPI && screen.logicalXDPI) {
ratio = screen.deviceXDPI / screen.logicalXDPI;
}
} else if (window.outerWidth !== undefined && window.innerWidth !== undefined) {
ratio = window.outerWidth / window.innerWidth;
}
if (ratio) {
ratio = Math.round(ratio * 100);
}
return ratio;
}
}
一个简单的vue兼容分辨率方案
最新推荐文章于 2023-12-13 14:33:01 发布