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

Detailed explanation of MySQL/Java server support for emoji and problem solving

This article describes the support and problem so...

HTML basics - CSS style sheets, style attributes, format and layout details

1. position : fixed Locked position (relative to ...

Analysis of the difference between HTML relative path and absolute path

HTML beginners often encounter the problem of how ...

How to deploy Vue project using Docker image + nginx

1. Packaging Vue project Enter the following name...

JS ES6 asynchronous solution

Table of contents Initially using the callback fu...

How to set mysql5.7 encoding set to utf8mb4

I recently encountered a problem. The emoticons o...

Detailed tutorial of using stimulsoft.reports.js with vue-cli

vue-cli uses stimulsoft.reports.js (nanny-level t...

Ubuntu terminal multi-window split screen Terminator

1. Installation The biggest feature of Terminator...

In-depth study of vue2.x--Explanation of the h function

Table of contents Solution, Summarize: vue projec...

Detailed tutorial for installing ffmpeg under Linux

1. Install ffmpeg under centos linux 1. Download ...

Using CSS3 to achieve transition and animation effects

Why should we use CSS animation to replace JS ani...