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

Zabbix monitors the process of Linux system services

Zabbix automatically discovers rules to monitor s...

Detailed explanation of MySQL partition table

Preface: Partitioning is a table design pattern. ...

MAC+PyCharm+Flask+Vue.js build system

Table of contents Configure node.js+nvm+npm npm s...

Object-Oriented Programming with XHTML and CSS

<br />If only XHTML and CSS were object-orie...

Detailed explanation of CocosCreator MVC architecture

Overview This article will introduce the MVC arch...

Implementation of formatting partitions and mounting in Centos7

Linux often encounters situations such as adding ...

Solution to Docker image downloading too slowly

Docker image download is stuck or too slow I sear...

Use IISMonitor to monitor web pages and automatically restart IIS

Table of contents 1. Tool Introduction 2. Workflo...

How to configure VMware multi-node environment

This tutorial uses CentOS 7 64-bit. Allocate 2GB ...

Vue v-model related knowledge summary

​v-model is a Vue directive that provides two-way...