Method 1 1. Configuration and installation steps: 1. Create a config folder under the src folder of the Vue project: 2. Create rem.js in the config folder: 3. Copy the following code into rem.js: // Base size const baseSize = 32 // Set rem function function setRem () { // The scaling ratio of the current page width relative to 750 width, which can be modified according to your needs. const scale = document.documentElement.clientWidth / 750 // Set the font size of the root node of the page document.documentElement.style.fontSize = (baseSize * Math.min(scale, 2)) + 'px' } // Initialize setRem() // Reset rem when changing window size window.onresize = function () { setRem() } 4. Introduce in main.js under the src folder: import './config/rem' 5. Import into the root directory of the Vue project: npm install postcss-pxtorem -D 6. Add to postcss.config.js in the Vue project folder: module.exports = { plugins: { autoprefixer: {}, "postcss-pxtorem": { "rootValue": 16, "propList": ["*"] } } } Method 2The first step is to install lib-flexible npm i lib-flexible --save Step 2: Install px2rem-loader npm install px2rem-loader --save-dev The third step is to introduce lib-flexible import 'lib-flexible/flexible' The fourth and most important step is to configure the utils file const px2remLoader = { loader: 'px2rem-loader', options: remUnit: 37.5 } }<br>//Add px2remLoader in the generateLoaders method 1 const loaders = [cssLoader,px2remLoader] Or step 4: module.exports = { chainWebpack: (config) => { config.module .rule('css') .test(/\.css$/) .oneOf('vue') .resourceQuery(/\?vue/) .use('px2rem') .loader('px2rem-loader') .options({ remUnit: 75 // 75 means the design draft of 750, 37.5 means the design draft of 375}) } } 1. Writing in px will be converted into rem format, but there are some places where we don’t want to convert. We can use the following two methods.
2 During use, it is found that some import external styles will not be converted. Be careful to avoid these pitfalls. <style src='../assets/style.css'> /* px2rem can convert normally*/ </style> <style> /* px2rem cannot convert normally */ @import '../assets/style.css'; </style> <style> /* px2rem cannot convert normally */ @import url('../assets/style.css'); </style> Method 3The first step is to install amfe-flexible npm i amfe-flexible -S The second step is to install postcss-pxtorem npm install postcss-pxtorem --save-dev The third step is to introduce amfe-flexible import 'amfe-flexible' Step 4 Create the postcss.config.js file in the root directory module.exports = { plugins: { 'postcss-pxtorem': { rootValue: 37.5, propList: ['*'] } } } SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: Linux RabbitMQ cluster construction process diagram
>>: MySQL spatial data storage and functions
Hello everyone, today I will share with you the i...
Recently, https has been enabled on the mobile ph...
MySQL row to column operation The so-called row-t...
Docker underlying technology: The two core techno...
In Linux systems, especially server systems, it i...
Designers need to understand psychology reading n...
This article example shares the specific code for...
The following script is used for scheduled backup...
<br />I have summarized the annotation writi...
This article shares the manual installation tutor...
Table of contents 1. Application Lifecycle 2. Pag...
The Nginx ngx_http_image_filter_module module (ng...
This article shares the specific code of js to ac...
First of all, let's talk about the execution ...
First look at the code and effect↓ <style> ...