参考文档
介绍amfe-flexible
amfe-flexible是配置可伸缩布局方案,主要是将1rem设为viewWidth/10。介绍postcss-pxtorem
postcss-pxtorem是postcss的插件,用于将像素(px)单元生成rem单位。amfe-flexible结合postcss-pxtorem
npm install amfe-flexible --save
npm install postcss-pxtorem@5.1.1
在main.js中导入amfe-flexible
```javascript import ‘amfe-flexible/index.js’
import ‘./assets/css/media.less’
<a name="hu1vq"></a>
#### 配置文2选1之:postcss.config.js文件
```javascript
module.exports = {
"plugins": {
'postcss-pxtorem': {
// rootValue: 37.5, // 换算的基数(设计图750的根字体为75)
rootValue: 192,
// selectorBlackList: ['.van-'], // 忽略转换正则匹配项
propList: ['*']
}
}
}
配置文2选1之:vue.config.js文件
module.exports = {
css: {
extract: true,
loaderOptions: {
postcss: {
plugins: [
require('postcss-pxtorem')({
rootValue: 192,
exclude: /node_modules\/vant|mobile/i, // 排除mobile和vant库
propList: ['*'],
selectorBlackList: ['.van-'] // 排除移动端使用了vant库
}),
require('postcss-pxtorem')({
rootValue: 37.5,
exclude: 'pc', // 排除pc
propList: ['*']
})
]
}
}
}
}
媒体查询动态显示
@media only screen and (max-width: 799px) {
.pc {
display: none !important;
}
.mobile {
display: block !important;
}
}
@media only screen and (min-width: 800px) {
.pc {
display: block !important;
}
.mobile {
display: none !important;
}
}