Detailed explanation of the adaptive adaptation problem of Vue mobile terminal

Detailed explanation of the adaptive adaptation problem of Vue mobile terminal

1. Create a project with vue ui

insert image description here

2. Select basic configuration items

insert image description here

3. Run the project

insert image description here

4. Create a new rem.js file

// 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()
} 

insert image description here

5. Import in main.js

import './utils/rem' 

insert image description here

6. Install postcss-pxtorem to automatically convert px to rem

npm install postcss-pxtorem -D 

insert image description here

7. Create a new .postcssrc.js file

module.exports = {
  "plugins": {
    "postcss-import": {},
    "postcss-url": {},
    // to edit target browsers: use "browserslist" field in package.json
    "autoprefixer": {},
    "postcss-pxtorem": {
      "rootValue": 32,
      "propList": ["*"]
    }
  }
} 

insert image description here

8. Continue to run and report an error

insert image description here

9. Create a new vue.config.js file (to solve the error in step 8)

module.exports = { 
  //Double-click the index.html file to run directly publicPath: './',
  // The directory for the production environment build files generated when running vue-cli-service build outputDir: 'dist',
  lintOnSave: true,
  // Whether to use a Vue build that includes a runtime compiler. After setting true, you can use template
  runtimeCompiler: true,
  //Whether to generate sourceMap file in production environment For details of sourceMap, please see the end productionSourceMap: false,
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') { // Modify config for production environment...
      return {

      }
    } else {
      return {

      }
    }
  },
  css: {
    extract: true, // Enable CSS source maps?
    sourceMap: false, // css preset configuration items modules: false,
    loaderOptions: {
      postcss: {
        plugins: [
          require('postcss-pxtorem')({
            rootValue: 37.5, // base of conversion selectorBlackList: ['weui', 'mu'], // ignore conversion regular matching items propList: ['*']
          })
        ]
      }
    }
  },

  // webpack-dev-server related configuration devServer: { // Set proxy hot: true, // Hot load host: '0.0.0.0', // IP address port: 8082, // Port https: false, // false turns off https, true turns it on open: true, // Automatically open the browser overlay: {
      warnings: false,
      errors: false
    }
  }
} 

insert image description here

10. Automatic adaptation completed

insert image description here

This is the end of this article about the detailed explanation of the adaptive adaptation problem of Vue mobile terminal. For more relevant Vue mobile terminal adaptive content, 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
  • A brief discussion on the perfect adaptation solution for Vue mobile terminal

<<:  Explanation of building graph database neo4j in Linux environment

>>:  Optimizing the performance of paging query for MySQL with tens of millions of data

Recommend

Implementation of Docker container state conversion

A docker container state transition diagram Secon...

Learn the black technology of union all usage in MySQL 5.7 in 5 minutes

Performance of union all in MySQL 5.6 Part 1:MySQ...

9 ways to show and hide CSS elements

In web page production, displaying and hiding ele...

Comparative Analysis of IN and Exists in MySQL Statements

Background Recently, when writing SQL statements,...

Get the IP and host name of all hosts on Zabbix

zabbix Zabbix ([`zæbiks]) is an enterprise-level ...

Vue implements image drag and drop function

This article example shares the specific code of ...

Docker deployment RabbitMQ container implementation process analysis

1. Pull the image First, execute the following co...

Encapsulation method of Vue breadcrumbs component

Vue encapsulates the breadcrumb component for you...

Six important selectors in CSS (remember them in three seconds)

From: https://blog.csdn.net/qq_44761243/article/d...

What you need to know about msyql transaction isolation

What is a transaction? A transaction is a logical...

Vue commonly used high-order functions and comprehensive examples

1. Commonly used high-order functions of arrays S...

Detailed explanation of Vue components

<body> <div id="root"> <...

Web page experience: planning and design

1. Clarify the design direction <br />First,...

How to implement the jQuery carousel function

This article shares the implementation code of jQ...