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

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

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>
相关推荐
SuperEugene1 分钟前
Vue3 + Element Plus 表格实战:批量操作、行内编辑、跨页选中逻辑统一|表单与表格规范篇
开发语言·前端·javascript
极梦网络无忧25 分钟前
基于 Vite + Vue3 的组件自动注册功能
前端·javascript·vue.js
Predestination王瀞潞38 分钟前
5.4.3 通信->WWW万维网内容访问标准(W3C):WWW(World Wide Web) 协议架构(分层)
前端·网络·网络协议·架构·www
爱学习的程序媛1 小时前
【Web前端】优化Core Web Vitals提升用户体验
前端·ui·web·ux·用户体验
zabr1 小时前
花了 100+ 篇笔记,我整理出 了一套 AI Agent 工程完全指南
前端·后端·agent
软弹1 小时前
深入理解 React Ref 机制:useRef 与 forwardRef 的协作原理
前端·javascript·react.js
YaHuiLiang1 小时前
Ai Coding浪潮下的前端:“AI在左,裁员在右”
前端
雪碧聊技术1 小时前
前端vue代码架子搭建
前端·javascript·vue.js·前端项目代码框架搭建
爱学习的程序媛1 小时前
【Web前端】前端用户体验优化全攻略
前端·ui·交互·web·ux·用户体验
han_1 小时前
JavaScript设计模式(二):策略模式实现与应用
前端·javascript·设计模式