在vue 中使用 less
在vue 中使用 less ,就可以使用rem了 如果项目已经开发的差不多了,没有用到rem 又要使用rem,您用这招。 postcss-pxtorem:转换px为rem的插件 postcss-pxtorem npm install postcss-pxtorem --save 新建 rem.js文件 const baseSize = 32 // 设置 rem 函数 function setRem () { // 当前页面宽度相对于 750 宽的缩放比例,可根据自己需要修改。 const scale = document.documentElement.clientWidth / 750 // 设置页面根节点字体大小 document.documentElement.style.fontSize = (baseSize * Math.min(scale, 2)) + 'px' } // 初始化 setRem() // 改变窗口大小时重新设置 rem window.onresize = function () { setRem() } 并引用进main.js文件内 import './rem' .postcssrc.js 在 px "postcss-pxtorem": { "rootValue": 32, "propList": ["*"] } helloworld.vue