1、安装过程请点击移步
postcss-pxtorem官网解释点击进入
2、这里只修改了1中的如下部分
postCssPxToRem({
rootValue ({ file }) {
return file.indexOf('vant') !== -1 ? 37.5 : 75
},
propList: ['*'],
selectorBlackList: ['van', 'jjw', /^\.aaa$/]
})
3、app.vue中的内容如下:
<template>
<div class="van-test">van-testdiv>
<div class="vvvan-test">vvvan-test-testdiv>
<div class="test">avan-testdiv>
<div class="jjw">jjw-testdiv>
template>
<script setup>
script>
<style scoped lang="less">
// 页面原样显示出来px没有转rem,说明以van开头的过滤掉了
.van-test{
height: 50px;
background-color: pink;
}
// 页面原样显示出来px没有转rem,说明只要包含van的都会被过滤掉
.vvvan-test{
height: 50px;
background-color: greenyellow;
}
// px转换成了rem
.test{
height: 50px;
background-color: deeppink;
}
// 原样显示,px没有转rem,说明可以排除多个
.jjw{
height: 50px;
background-color: yellow;
}
style>
4、显示结果:


exclude:(String, Regexp, Function) The file path to ignore and leave as px.表示的是排除以文件形式设置的样式例如:
selectorBlackList: ['van', 'jjw', /^\.aaa$/],
exclude: 'test'
app.vue中的style中导入样式