<script>
mounted() {
//获取屏幕宽度(viewport)
let htmlWidth =
window.innerWidth ||
document.documentElement.clientWidth ||
document.body.clientWidth;
//获取html的dom
let htmlDom = document.getElementsByTagName("html")[0];
//设置html的fontsize
htmlDom.style.fontSize = htmlWidth / 95 + "px";
//屏幕变化时html字体变化
window.addEventListener("resize", e => {
let htmlWidth =
window.innerWidth ||
document.documentElement.clientWidth ||
document.body.clientWidth;
htmlDom.style.fontSize = htmlWidth / 95 + "px";
});
}
</script>
<style>
@function px2rem($px) {
$rem: 10px;
@return ($px/$rem) + rem;
}
</style>