大屏自适应,响应式布局,亲测有效

前言:只要是驾驶舱项目或者项目中都会用到自适应模块,切不能让各模块错乱分布,核心代码就这几行,拿去用吧

javascript 复制代码
// App.vue
<template>
//---------
    <div id="integration" class="pageContent" :style="integrationStyle">
           <RouterView />
    </div>
//---------
</template>
<script lang="ts" setup>
    // 修改 integrationStyle 的定义
    const integrationStyle = ref({});

    // 修改 resizeMain 函数
    const resizeMain = () => {
  
    // 直接获取当前窗口尺寸
    const width = window.innerWidth;
    const height = window.innerHeight;
  
    let [defWidth, defHeight] = [0, 0];
    const w = (width - defWidth) / 1920;
    const h = (height - defHeight) / 1080;
  
    // 直接赋值
    integrationStyle.value = {
        transform: `scaleY(${h}) scaleX(${w})`,
        width: '1920px',
        height: '1080px'
      };
    };
    // 确保 DOM 加载完成后初始化一次
    onMounted(() => {
      resizeMain();
      window.addEventListener('resize', resizeMain);
    });

    onBeforeUnmount(() => {
      window.removeEventListener('resize', resizeMain);
    });


</script>
<style scoped lang="less">
  #integration {
	transform-origin: left top;
	position: fixed;
	left: 0;
	top: 0;
  }
</style>
相关推荐
Bigger1 分钟前
第四章:我是如何扒开 Claude Code 记忆与上下文压缩机制的
前端·claude·源码阅读
还在忙碌的吴小二5 分钟前
在 Mac 上安装并通过端口调用 Chrome DevTools MCP Server(谷歌官方 MCP 服务器)
服务器·前端·chrome·macos·chrome devtools
灵感__idea8 小时前
Hello 算法:贪心的世界
前端·javascript·算法
GreenTea9 小时前
一文搞懂Harness Engineering与Meta-Harness
前端·人工智能·后端
周末也要写八哥10 小时前
html网页设计适合新手的学习路线总结
html
killerbasd11 小时前
牧苏苏传 我不装了 4/7
前端·javascript·vue.js
吴声子夜歌11 小时前
ES6——二进制数组详解
前端·ecmascript·es6
码事漫谈11 小时前
手把手带你部署本地模型,让你Token自由(小白专属)
前端·后端
ZC跨境爬虫11 小时前
【爬虫实战对比】Requests vs Scrapy 笔趣阁小说爬虫,从单线程到高效并发的全方位升级
前端·爬虫·scrapy·html
爱上好庆祝11 小时前
svg图片
前端·css·学习·html·css3