如何在vue-cli3中使用postcss-px2rem

在src目錄下建立 viewport.jscss

文件下載:https://github.com/imochen/hotcss/tree/master/srcvue

這個JS是用來在頁面打開的時候給HTML根加上適配的字體大小git

而後在main.js下添加:github

import './viewport.js'
 
這裏強調下爲何不使用lib-flexible插件
我的在使用lib-flexible插件時,感受沒hotcss友好,
lib-flexible在頁面打開的時候,內容渲染完了纔在HTML根上添加適配,這樣頁面會從新渲染一次,致使內容從大變小,或從小變大這樣的BUG。
而hotcss就沒這個問題。
 
接下來要安裝換算PX換算REM插件
cnpm install postcss-px2rem --save

而後在 vue.config.js加入:npm

module.exports = {
    lintOnSave: false,//關閉eslint
    css: {
        loaderOptions: {
            postcss: {
                plugins: [
                    require('postcss-px2rem')({remUnit: 75}), // 換算的基數
                ]
            }
        }
    }
}post

最後重啓字體

內容參考:https://blog.csdn.net/u010214074/article/details/84841496flex

相關文章
相關標籤/搜索