vue自适应布局的n中方法

在index.html中

head标签中

  <script>
    //通过window.screen.width获取屏幕的宽度
    var offWidth = window.screen.width / 375; //这里用宽度/30表示1rem取得的px
    document.getElementsByTagName("html")[0].style.fontSize = offWidth + 'px'; //把rem的值复制给顶级标签html的font-size

  </script>

cnpm i lib-flexible -S
cnpm i postcss-pxtorem -D

postcss.config.js

module.exports = {
  plugins: {
    autoprefixer: {},
    'postcss-pxtorem': {
      'rootValue': 75, // 设计稿宽度的1/10,(JSON文件中不加注释,此行注释及下行注释均删除)
      'propList': ['*'] // 需要做转化处理的属性,如`hight`、`width`、`margin`等,`*`表示全部
    }
  }
}

main.js
import 'lib-flexible'

验证

<html data-dpr="1" style="font-size: 37.4917px;" lang="en">
posted @ 2019-05-25 11:57  仲灏  阅读(353)  评论(0编辑  收藏  举报