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

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

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>
相关推荐
hoLzwEge16 分钟前
node-linker VS shamefully-hoist
前端·前端框架
袋鱼不重22 分钟前
解决 Web 端图片预览与下载颜色不一致的一种工程方案
前端·后端
风止何安啊28 分钟前
教你用 JS + AI 实现简单的爬虫,零门槛爬取网页信息
前端
cidy_9829 分钟前
codebase-memory-mcp 新手完全教程:让 AI 真正「理解」你的代码库
前端
牛奶36 分钟前
HTTPS你不知道的事
前端·https·浏览器
小小小小宇38 分钟前
前端 Vue 如何避免不必要的子组件渲染全解析
前端
cidy_981 小时前
codebase-memory-mcp 安装教程
前端
mt_z2 小时前
Webpack 与 Vite 完全指南
前端
灏仟亿前端技术团队2 小时前
B 端多弹窗越来越难维护?试试把弹窗交互 Promise 化
前端
奇奇怪怪的2 小时前
向量数据库选型与生产级实战
前端