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?
CSS style specifications 1. Class Selector 2. Tag...
When I first started setting up an ftp server on ...
To back up multiple databases, you can use the fo...
Using mask layers in web pages can prevent repeat...
webpack loads css files and its configuration Aft...
Table of contents 【Effect】 【Implementation method...
Table of contents need: Problems encountered: sol...
This article example shares the specific code of ...
Preface This article mainly introduces the use an...
Copy code The code is as follows: <html> &l...
Table of contents Preface Can typeof correctly de...
What is content overflow? In fact, when there is ...
1.device-width Definition: Defines the screen vis...
background I am often asked about database transa...
Table of contents 1. Check whether the docker env...