vue3 element-plus rem
时间: 2023-11-11 12:06:20 浏览: 264
在Vue3中使用element-plus库时,可以通过以下步骤设置rem单位:
1. 在项目的入口文件main.js中,引入element-plus的样式文件和适配rem的工具函数:
```javascript
import 'element-plus/lib/theme-chalk/index.css';
import { adapt } from 'element-plus/lib/utils/dom';
// 设置rem适配
adapt(document.documentElement.clientWidth);
window.addEventListener('resize', () => {
adapt(document.documentElement.clientWidth);
});
```
2. 在项目的根目录下创建一个postcss.config.js文件,配置postcss-pxtorem插件:
```javascript
module.exports = {
plugins: {
'postcss-pxtorem': {
rootValue: 16,
propList: ['*'],
},
},
};
```
其中rootValue表示1rem对应的像素值,默认为16。
3. 使用vue-cli创建的项目默认已经配置了postcss-loader,所以无需再额外安装和配置。如果你是手动配置的项目,请确保已经安装了postcss-loader和postcss-pxtorem插件。
以上是在Vue3中使用element-plus库适配rem单位的步骤。希望对你有帮助!
阅读全文
相关推荐


















