1.搭建项目
vue create 项目名称
选择自定义设置
cd 项目名
yarn serve
2.自定义rem布局
public 下新建js 文件
public > js > rem.js
function remsize() {
// 获取宽度
var width = document.documentElement.clientWidth || window.innerWidth
if(width >= 750) {
width = 750
}
// 如果设计稿为750
// 设置一半的宽度为375
// 1rem === 100px
// 那么一半的宽度 为3.75rem
if(width <= 320) {
width = 320
}
document.documentElement. style.fontSize = (width / 7.5 ) + 'px'
document.querySelector('body').style.fontSize = 0.16 + 'rem'
}
// 当浏览器被重置大小时执行
window.onresize = function {
remsize()
}
将rem.js 引入index.html