vue前端可视化大屏页面适配方案

参考了其他博主的代码,但发现会有滚动条,并且居中的位置不太对,所以改了一下css,修复了这些问题,直接上代码

javascript 复制代码
<template>
<div class="ScaleBoxA">
    <div
      class="ScaleBox"
      ref="ScaleBox"
      :style="{
        width: width + 'px',
        height: height + 'px',
      }"
    >
         <!--  内容  -->
     </div>
</div>
</template>
<script>
export default {
   name: 'index',
   data() {
    return {
      scale: 0,
      width: 1920,
      height: 1080,
     }
    }, 
   methods: {
    getScale() {
      const { width, height } = this
      const wh = window.innerHeight / height
      const ww = window.innerWidth / width
      return ww < wh ? ww : wh
    },
    setScale() {
      this.scale = this.getScale()
      if (this.$refs.ScaleBox) {
        this.$refs.ScaleBox.style.setProperty('--scale', this.scale)
      }
    },
    debounce(fn, delay) {
      const delays = delay || 500
      let timer
      return function () {
        const th = this
        const args = arguments
        if (timer) {
          clearTimeout(timer)
        }
        timer = setTimeout(function () {
          timer = null
          fn.apply(th, args)
        }, delays)
      }
    },
  },
  mounted() {
    this.setScale()
    window.addEventListener('resize', this.debounce(this.setScale))
  },
}
<style lang="scss" scoped>
#ScaleBox {
  --scale: 1;
}
.ScaleBoxA {
  top: 0;
  width: 100vw;
  height: 100vh;
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ScaleBox {
  transform: scale(var(--scale));
  display: flex;
  flex-direction: column;
  transform-origin: 960px 540px;
  transition: 0.3s;
  z-index: 999;
}
</style>
相关推荐
朝阳394 小时前
React【面试】
前端·react.js·面试
沐知全栈开发4 小时前
jQuery Mobile 事件详解
开发语言
漓漾li4 小时前
每日面试题(2026-05-15)- 前端
前端·vue.js·react.js
进击切图仔4 小时前
RAG 加载 pdf 文档
linux·前端·pdf
小小小小宇5 小时前
git 大仓库拉取卡顿问题
前端
前端那点事5 小时前
告别低级冗余!10个前端原生高阶技巧,让代码更优雅、性能更出众
前端·vue.js
hexu_blog5 小时前
前端vue后端java如何实现证件照功能
前端·javascript·vue.js
豹哥学前端5 小时前
前端 LocalStorage 实战:从入门到熟练,一篇就够了
前端·javascript·面试
用户40189933422845 小时前
第 11 章 MCP 协议与集成
前端
知识分享小能手5 小时前
R语言入门学习教程,从入门到精通,R语言获取数据 (8)
开发语言·学习·r语言