Preface: Based on a recent medical mobile project, how does Vue adapt to different screen sizes on different screens? 1. Adaptation solution The vue mobile solution I used in this project is a combination of amfe-flexible and postcss-pxtorem). First, let me introduce amfe-flexible amfe-flexible is a flexible layout configuration scheme, mainly setting 1rem to viewWidth/10. Then there is this library postcss-pxtorem postcss-pxtorem is a postcss plugin that converts pixel units to rem units. 2. How to use and configure?1. Install amfe-flexible and postcss-pxtorem npm install amfe-flexible --save npm install postcss-pxtorem --save 2. After the installation is complete, it must be introduced before it can be used We need to import it in main.js to use it import 'amfe-flexible'; This import is OK 3. Then comes the postcss-pxtorem configuration steps To configure postcss-pxtorem, you can configure it in one of vue.config.js, .postcssrc.js, and postcss.config.js. The weight decreases from left to right. If there is no such file, create a new file. You only need to set one of them: For convenience, I configured the code in vue.config.js as follows: module.exports = { //...other configuration css: { loaderOptions: { postcss: { plugins: [ require('postcss-pxtorem')({ rootValue: 37.5, propList: ['*'] }) ] } } }, } Configure in .postcssrc.js or postcss.config.js as follows: module.exports = { "plugins": { 'postcss-pxtorem': { rootValue: 37.5, propList: ['*'] } } } Note: With the above configuration we can use it in the project. For example, in our project we write: .login-form { width: 90%; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #fff; padding: 20px; box-sizing: border-box; border-radius: 10px; .title { position: absolute; top: -50px; font-size: 24px; color: #fff; left: 0; right: 0; text-align: center; } } Then the output of our code is as follows, and the plug-in helps us convert units automatically. login-wraper .login-form { width: 90%; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); background-color: #fff; padding: .53333rem; // Note that this is the converted unit box-sizing: border-box; border-radius: .26667rem; // Note that this is the converted unit} This is the end of this article about the perfect adaptation solution for vue mobile terminals. For more relevant content about the perfect adaptation solution for vue mobile terminals, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Three ways to avoid duplicate insertion of data in MySql
>>: How does MySQL implement ACID transactions?
Preface CSS grids are usually bundled in various ...
The implementation of expanding and collapsing li...
This article mainly introduces an example of how ...
1. Apache server installation and configuration y...
For work needs, I found a lot of information on t...
A brief description of environment variable confi...
By right-clicking the source file, the following c...
When joining a Windows 2008 server subdomain to a...
Installation path: /application/mysql-5.5.56 1. P...
Here are a few ways to remove it: Add the link dir...
If you upgrade in a formal environment, please ba...
Before installing Tomcat, install the JDK environ...
This article shares with you the graphic tutorial...
Table of contents 1. Download WeChat developer to...
Practice is the only way to test the truth. This ...