1,不生效代码
const body = document.getElementsByTagName('body')[0];
const html = document.getElementsByTagName('html')[0];
const width = html.clientWidth;
const height = html.clientHeight;
const max = width > height ? width : height;
const min = width > height ? height : width;
body.style.width = max + "px !important";
body.style.height = min + "px !important";
2,几种解决后生效的的代码
const body = document.getElementsByTagName('body')[0];
const html = document.getElementsByTagName('html')[0];
const width = html.clientWidth;
const height = html.clientHeight;
const max = width > height ? width : height;
const min = width > height ? height : width;
//第一种解决方案
body.style.setProperty('height', min+"px", 'important')
body.style.setProperty('width', max+"px", 'important')
//第二种解决方案
//body.style.cssText=`height:${min+"px"} !important;width:${max+"px"} !important;`