使用rem適配移動端
在main.js設置字體大小
//以屏幕寬度爲375爲例
const winWidth = window.innerWidth;//獲取屏幕寬度
const fontSize = winWidth / 375 * 20;
document.getElementsByTagName('html')[0].style.fontSize = fontSize + 'px';//設置根元素字體
<div class="home">
<img alt="Vue logo" src="../assets/logo.png">
</div>
- 使用less
/* *.less */
@r:40rem; /*設計稿寬度以750爲例*/
.home{
width: 750/@r;
}