1. 下載 npm install -s postcss-plugin-px2rem
2.在根文件夾中創建 .postcssrc.js
module.exports = {
"plugins": {
"postcss-plugin-px2rem": {
rootValue: 100,
}
}
}
3.創建rem.js 文件 ,因為這個插件 只會轉成rem,並不會設置頁面字體 大小
(function () {
var clientWidth = document.documentElement ? document.documentElement.clientWidth : document.body.clientWidth;
if (clientWidth > 750) clientWidth = 750;
document.documentElement.style.fontSize = clientWidth * 1 / 3.75 + "px";
return clientWidth * 1 / 3.75;
})();
4. 在main.js導入 rem.js