This article example shares the specific code for vue large screen display adaptation for your reference. The specific content is as follows 1. Create a file cv in the utils folder with the following code export function useIndex(appRef) { // * appRef points to the outermost container // * Timing function let timer = null // * Default scaling value const scale = { width: '1', height: '1' } // * Design draft size (px) const baseWidth = 1920 const baseHeight = 1080 // * The ratio to be maintained (default 2) // const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5)) const baseProportion = 2 const calcRate = () => { // Current aspect ratio const currentRate = parseFloat((window.innerWidth / window.innerHeight).toFixed(5)) if (appRef) { if (currentRate > baseProportion) { // Indicates wider scale.width = ((window.innerHeight * baseProportion) / baseWidth).toFixed(5) scale.height = (window.innerHeight / baseHeight).toFixed(5) appRef.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)` } else { // Indicates higher scale.height = ((window.innerWidth / baseProportion) / baseHeight).toFixed(5) scale.width = (window.innerWidth / baseWidth).toFixed(5) appRef.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)` } } } const resize = () => { clearTimeout(timer) timer = setTimeout(() => { calcRate() }, 200) } // Change the window size and redraw const windowDraw = () => { window.addEventListener('resize', resize) } return { appRef, calcRate, windowDraw } } 2.app.vue structure style <template> <div ref="appRef" class="main"> <div class="layout-container"> </div> </div> </template> <script> import { useIndex } from '@/utils/utilsDram.js' export default { mounted () { const { calcRate, windowDraw } = useIndex(this.$refs.appRef) calcRate() windowDraw() } } </script> <style lang="scss" scoped> .main { color: #d3d6dd; width: 1920px; height: 1080px; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); transform-origin: left top; .layout-container { width: 100%; height: 100%; } } </style> 3. The font size and box width are directly set to px. No matter how you zoom in or out, it will remain the same as before. The basic page size will not be too different. The following figure shows the effect of zooming in 500 times. 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:
|
<<: Write a formal blog using XHTML CSS
>>: Windows Server 2016 Quick Start Guide to Deploy Remote Desktop Services
Overview One of the most powerful features of MyS...
Table of contents Preface 1. Download MySQL from ...
Table of contents 1. Teleport usage 2. Complete t...
1. Text around the image If we use the normal one...
1. Environment version Docker version 19.03.12 ce...
Detailed explanation of the order of Mysql query ...
Copy code The code is as follows: <!DOCTYPE ht...
Table of contents Using slots in Vue: slot Scoped...
Table of contents MyISAM and InnoDB Reasons for p...
1. Brief Introduction Vue.js allows you to define...
Give time time and let the past go. In the previo...
Here are two ways to install MySQL under Linux: y...
I recently encountered a problem when doing IM, a...
This article example shares the specific code of ...
Table of contents Preface introduce 1. Mechanism ...