(function(){function a(){var b=document.documentElement.clientWidth;b=b>750?750:b;var c=b/750*100;document.getElementsByTagName("html")[0].style.fontSize=c+"px"}a();window.onresize=a})();
import ‘./config/rem‘
npm install postcss-pxtorem -D
module.exports = { plugins: { autoprefixer: {}, "postcss-pxtorem": { "rootValue": 32, "propList": ["*"] } } }
至此,Vue 项目就能实现在页面中自动将 px 转换成 rem 了
假如给出设计图是 375*812,可以在代码中直接写入:
div{ width: 375px; height: 812px; }
此时在页面中显示:
如果要让部分属性不转换成 rem,可以将 px 写成 Px:
div{ width: 375Px; height: 812px; }
这时在页面中就会保留 375px 了:
原文:https://www.cnblogs.com/Leophen/p/11283677.html