关于vue在PC端,rem对不同屏幕进行适配
1.新建rem.js文件
// rem等比适配配置文件 // 基准大小 const baseSize = 16 // 设置 rem 函数 function setRem () { // 当前页面屏幕分辨率相对于 1920宽的缩放比例,可根据自己需要修改 const scale = document.documentElement.clientWidth / 1920 // 设置页面根节点字体大小(“Math.min(scale, 2)” 指最高放大比例为2,可根据实际业务需求调整) document.documentElement.style.fontSize = baseSize * Math.min(scale, 2) + 'px' } // 初始化 setRem() // 改变窗口大小时重新设置 rem window.onresize = function () { setRem() }
2.在项目的入口文件main.js中引入import ‘@/utils/rem.js’
3.在vue项目中创建postcss.config.js文件,并且下载依赖 npm install postcss-pxtorem --save
module.exports = { plugins: { autoprefixer: {}, 'postcss-pxtorem': { rootValue: 16, propList: ['*'], selectorBlackList: ['.norem'], exclude: /node_modules/i } } }