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

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

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>
相关推荐
刘发财3 小时前
弃用html2pdf.js,这个html转pdf方案能力是它的几十倍
前端·javascript·github
牛奶5 小时前
2026年大模型怎么选?前端人实用对比
前端·人工智能·ai编程
牛奶5 小时前
前端人为什么要学AI?
前端·人工智能·ai编程
Kagol8 小时前
🎉OpenTiny NEXT-SDK 重磅发布:四步把你的前端应用变成智能应用!
前端·开源·agent
GIS之路9 小时前
ArcGIS Pro 中的 notebook 初识
前端
JavaGuide9 小时前
7 道 RAG 基础概念知识点/面试题总结
前端·后端
ssshooter10 小时前
看完就懂 useSyncExternalStore
前端·javascript·react.js
格砸10 小时前
从入门到辞职|从ChatGPT到OpenClaw,跟上智能时代的进化
前端·人工智能·后端
Live0000011 小时前
在鸿蒙中使用 Repeat 渲染嵌套列表,修改内层列表的一个元素,页面不会更新
前端·javascript·react native
柳杉11 小时前
使用Ai从零开发智慧水利态势感知大屏(开源)
前端·javascript·数据可视化