• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

vue 实现响应式布局,移动pc端通用amfe-flexible和postcss-pxtorem结合使用

武飞扬头像
yawhom
帮助1

1.amfe-flexible是配置可伸缩布局方案,主要是将1rem设为viewWidth/10。

2.postcss-pxtorem是postcss的插件,用于将像素单元生成rem单位。

3.安装amfe-flexible和postcss-pxtorem:

npm install amfe-flexible -S

npm install postcss-pxtorem -S

  1.  
    npm install amfe-flexible -S
  2.  
    npm install postcss-pxtorem -S

在main.js引入amfe-flexible

import 'amfe-flexible';

在vue.config.js添加配置postcss-pxtorem;(注意:可在vue.config.js、.postcssrc.js、postcss.config.js其中之一配置,权重从左到右降低,没有则新建文件,只需要设置其中一个即可)

  1.  
    module.exports = {
  2.  
    css:{
  3.  
    loaderOptions:{
  4.  
    postcss:{
  5.  
    plugins:{
  6.  
    require('postcss-pxtorem')({
  7.  
    rootValue:192, // ui设计图/10,可以根据项目的UI图定义
  8.  
    propList:['*']
  9.  
    })
  10.  
    }
  11.  
    }
  12.  
    }
  13.  
    }
  14.  
    }

对于需要特殊元素需要设置的字体自适应,如echarts字体,可以在utils封装一个字体自适应的方法

  1.  
    export function setAutoFontSize(font){
  2.  
    let clientWidth = window.innerWidth || document.documentElement.clientWidth ||
  3.  
    document.body.clientWidth;
  4.  
    if(clientWidth){
  5.  
    let fontRate = clientWidth/1920 // clientWidth/设计图宽度
  6.  
    return font*fontRate;
  7.  
    }
  8.  
    }

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhihabeg
系列文章
更多 icon
同类精品
更多 icon
继续加载