Vue realizes screen adaptation of large screen pages

Vue realizes screen adaptation of large screen pages

This article shares the specific code of Vue to achieve screen adaptation of large-screen pages for your reference. The specific content is as follows

1. Set the size of the large screen design to 1920*1080 in the configuration file

//appConfig.js
export default{
    screen:{
        width:1920,
        height:1080,
        scale:20
    }//Large screen design width and height}

2. Define resetScreenSize.js

import appConfig from '../config/base'
 
export function pageResize(callback) {
    let init = () => {
        console.log(window.innerHeight + "," + window.innerWidth);    
        let _el = document.getElementById('app');
       
        let hScale = window.innerHeight / appConfig.screen.height;
        let wScale = window.innerWidth / appConfig.screen.width;
        let pageH = window.innerHeight;
        let pageW = window.innerWidth;
       
        let isWider = (window.innerWidth / window.innerHeight) >= (appConfig.screen.width / appConfig.screen.height);
        console.log(isWider);
        if (isWider) {
                _el.style.height = window.innerHeight+'px'; // '100%';
                _el.style.width = pageH * appConfig.screen.width / appConfig.screen.height + 'px';
                _el.style.top='0px';
                _el.style.left=(window.innerWidth -pageH * appConfig.screen.width / appConfig.screen.height)*0.5+'px';
                console.log(_el.style.width + "," + _el.style.height)
        }
        else {
                _el.style.width = window.innerWidth+'px'; // '100%';
                _el.style.height = pageW * appConfig.screen.height / appConfig.screen.width + 'px';
                _el.style.top = 0.5*(window.innerHeight-pageW * appConfig.screen.height / appConfig.screen.width)+'px';
                _el.style.left='0px';
                console.log(_el.style.height);
                console.log(_el.style.top);
        }
        document.documentElement.style.fontSize = (_el.clientWidth / appConfig.screen.scale) + 'px';
 
      
    }    
    var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
    window.addEventListener(resizeEvt, init, false);
    document.documentElement.addEventListener('DOMContentLoaded', init, false);
    init()
}

3 Usage

main.js import

import appConfig from './config/base.js';
Vue.prototype.appConfig=appConfig;
app.Vue import {pageResize} from './utils/resetScreenSize' in the mounted function
 
export default {
  name: 'App',
  data(){
    return {
       
    }
  },
  mounted(){
    pageResize();
    console.log('pageResize');
  }
}

Style lang="stylus" in the component

 .mc{
        display :flex;
        flex-direction :column;
        align-content :center;
        justify-content :center;  
        display: flex;
        flex: 1 1 auto;
        flex-direction: column;
        padding:(15/96)rem;
    }
 
    .leftC{
       width: (410/96)rem;
    }
 
    .centerC{
       width: (1060/96)rem;
    }
 
    .rightC{
       width: (450/96)rem;
    }

96 is derived from 1920/20 in the configuration file, so there is no need to perform various conversions.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • VUE develops the background management page steps of the distributed medical registration system
  • Example steps for VUE to build a distributed medical registration system backend management page
  • How to implement page jump in Vue project
  • VUE develops hospital settings page steps for distributed medical registration system

<<:  Detailed explanation of the persistence implementation principle of transactions in MySQL

>>:  HTML validate HTML validation

Recommend

How to use CSS to achieve two columns fixed in the middle and adaptive

1. Use absolute positioning and margin The princi...

How to automatically number the results of MYSQL query data

Preface In fact, I have never encountered this ki...

JavaScript manual implementation of instanceof method

1. Usage of instanceof instanceof operator is use...

Summary of MySQL Undo Log and Redo Log

Table of contents Undo Log Undo Log Generation an...

Implementing a simple whack-a-mole game in JavaScript

This article shares the specific code for JavaScr...

TCP performance tuning implementation principle and process analysis

Three-way handshake phase Number of retries for c...

Docker installation tutorial in Linux environment

1. Installation environment Docker supports the f...

How to delete extra kernels in Ubuntu

Step 1: View the current kernel rew $ uname -a Li...

Detailed explanation of two ways to dynamically change CSS styles in react

The first method: dynamically add a class to show...

MySQL 5.7.18 Installer installation download graphic tutorial

This article records the detailed installation tu...

Example statements for indexes and constraints in MySQL

Foreign Keys Query which tables the primary key o...

Detailed explanation of count without filter conditions in MySQL

count(*) accomplish 1. MyISAM: Stores the total n...

Solution to invalid Nginx cross-domain setting Access-Control-Allow-Origin

nginx version 1.11.3 Using the following configur...