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>
相关推荐
SuperEugene1 小时前
Vue/Vite 多环境配置实战:dev、test、prod 差异区分与避坑指南|Vue 工程化篇
前端·javascript·vue.js
结网的兔子2 小时前
前端学习笔记(实战准备篇)——用vite构建一个项目【吐血整理】
前端·学习·elementui·npm·node.js·vue
kyriewen2 小时前
盒模型:CSS 世界的物理法则,margin 塌陷与 padding 的恩怨情仇
前端·css·html
lichenyang4532 小时前
React 性能优化组件设计模式与通信
前端·javascript·设计模式
小成C2 小时前
别再把 Claude Code 用乱了:CLAUDE.md、Rules、Skills、Hooks 到底怎么分工?
前端·人工智能·面试
巫山老妖2 小时前
OpenClaw 技术教程大全:从安装到多 Agent 协作,全在这里
java·前端
weixin_446260852 小时前
提升开发效率的神器!快速选择编码上下文 — React Grab
前端·react.js·前端框架
前端付豪2 小时前
自动学习建议解决薄弱知识点
前端·python·openai
SuperEugene2 小时前
Vite 实战教程:alias/env/proxy 配置 + 打包优化避坑|Vue 工程化篇
前端·javascript·vue.js·状态模式·vite