A brief discussion on the perfect adaptation solution for Vue mobile terminal

A brief discussion on the perfect adaptation solution for Vue mobile terminal

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:
1. Set rootValue according to the width of the design divided by 10. Here, assuming the design is 375, rootValue is set to 37.5.
2. propList is used to set the properties that need to be converted. Here, * means all properties are converted.

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:
  • Vue uses rem to achieve mobile screen adaptation
  • Vue is the best solution for mobile adaptation (tested and effective)
  • Detailed explanation of the adaptation of Vue mobile projects (taking mint-ui as an example)
  • Detailed explanation of vue mobile adaptation solution
  • Detailed explanation of Vue mobile screen adaptation
  • Solve the vue mobile adaptation problem
  • Detailed explanation of the adaptive adaptation problem of Vue mobile terminal

<<:  Three ways to avoid duplicate insertion of data in MySql

>>:  How does MySQL implement ACID transactions?

Recommend

HTML (css style specification) must read

CSS style specifications 1. Class Selector 2. Tag...

Illustration of the process of using FileZilla to connect to the FTP server

When I first started setting up an ftp server on ...

MySQL common backup commands and shell backup scripts sharing

To back up multiple databases, you can use the fo...

How to implement mask layer in HTML How to use mask layer in HTML

Using mask layers in web pages can prevent repeat...

Webpack loads css files and its configuration method

webpack loads css files and its configuration Aft...

Example of Vue implementing fixed bottom component

Table of contents 【Effect】 【Implementation method...

Element Table table component multi-field (multi-column) sorting method

Table of contents need: Problems encountered: sol...

vue+tp5 realizes simple login function

This article example shares the specific code of ...

HTML head tag meta to achieve refresh redirection

Copy code The code is as follows: <html> &l...

Examples of correct judgment methods for data types in JS

Table of contents Preface Can typeof correctly de...

About the layout method of content overflow in table

What is content overflow? In fact, when there is ...

Mybatis statistics of the execution time of each SQL statement

background I am often asked about database transa...

Detailed steps for installing MinIO on Docker

Table of contents 1. Check whether the docker env...