vue 大屏适配的一种实现思路

大屏适配的一种实现思路

以设计稿为 1920*1080px为例, 开发时按设计稿开发

根据屏幕大小缩放页面, 已达到适配的目的, 必须是等比较缩放,否则会出现空白

html 复制代码
<template>
  <div class="dashboard-container">
    <div id="dashboardBox" :style="{ transform: transformStyle }">
      <!-- 顶部标题栏 -->
      <header class="page-header"></header>

      <!-- 左侧模块 -->
      <aside class="left-panel">
      </aside>

      <!-- 中间底部模块 -->
      <section class="center-bottom-panel">
      </section>

      <!-- 右侧模块 -->
      <aside class="right-panel">
      </aside>
    </div>

  
  </div>
</template>

<script>

export default {
  computed: {
    transformStyle() {
        //设计稿1920*1080
      const baseHeight = 1080
      const scaleValue = this.windowHeight / baseHeight
      return `scale(${scaleValue}, ${scaleValue}) translate(-50%, -50%)`
    },
  },
  data() {
    return {
      windowHeight: window.innerHeight,
    }
  },
  mounted() {
    window.addEventListener('resize', this.handleResize)
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.handleResize)
  },
  methods: {
    handleResize() {
      this.windowHeight = window.innerHeight
    },
  },
}
</script>

<style lang="scss" scoped>
/* 全局样式 */
.dashboard-container {
  width: 100vw;
  height: 100vh;
  background-color: #050d19;
  background-image: radial-gradient(circle at 50% 0%, #1a3a5a 0%, #050d19 70%);
  color: #fff;
  font-family: 'Microsoft YaHei', sans-serif;
  overflow: auto;
  position: relative;
}

#dashboardBox {
  width: 1920px;
  height: 1080px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  transform-origin: left top;
  overflow: hidden;
}
</style>
相关推荐
xywww1682 分钟前
真实后台页实测:Opus 5 看图写前端的可用边界在哪
linux·服务器·前端·数据库·人工智能·gpt
小小尚@21 分钟前
AE脚本-AE Actions v1.1.8 操作动作记录器
开发语言·前端·javascript·jupyter·postman
大家的林语冰1 小时前
👍 超越 ESLint,Oxc 优先采用 TypeScript 7,Rust 和 Go 梦幻联动!
前端·javascript·typescript
樊小肆2 小时前
# 你还在等DeepSeek官方 agent Harness‌? 来试试 DeepSeeker-Code吧
前端·人工智能·后端
樊小肆2 小时前
2568 万 token 才花 2 块 2:聊聊 DeepSeeker-Code 怎么吃满上下文缓存
前端·人工智能·后端
JarvanMo2 小时前
Flutter 3.47: material/cupertino终于解耦了
前端
郭邯3 小时前
一次「字符洁癖」引发的思考:我用 AI 写了个全角半角转换工具
前端
想要成为糕糕手3 小时前
🚀 在浏览器里跑 DeepSeek-R1?WebGPU 端侧推理实战(五)—— 中断、重置、缓存与流式生成
前端·react.js·llm
GuWenyue3 小时前
后端接口又双叒没写好?3 步搭建前端 Mock,从此告别"傻等后端"
前端·mocha
海兰3 小时前
【数据采集】开源的 Web 数据采集与处理Firecrawl(一)
前端·开源