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>
相关推荐
青山Coding16 小时前
Cesium应用(八):物体运动的实现思路
前端·cesium
用户416596736935516 小时前
Android WebView 加载 file:// 离线页面调试教程
android·前端
Asmewill16 小时前
curl命令学习笔记一
前端
我是一只快乐的小螃蟹16 小时前
1.2 ArrayList 源码解析
前端
星栈16 小时前
我用 Rust + Dioxus 做了个全栈跨平台笔记应用:再把新建、编辑和交付补上
前端·rust·前端框架
我是一只快乐的小螃蟹16 小时前
1.1 HashMap (JDK1.8) 源码解析
前端
爱勇宝19 小时前
小红花成长新版:模板来了,鼓励也更容易开始
前端·后端·程序员
竹林81820 小时前
Solana前端开发:我在一个NFT铸造页面上被@solana/web3.js的Connection和Transaction签名坑了两天
前端
冬奇Lab20 小时前
每日一个开源项目(第144篇):ai-website-cloner-template - 一条命令、多 Agent 并行,把任意网站逆向成 Next.js 代码
前端·人工智能·开源
玄玄子20 小时前
webpack publicPath作用原理
前端·webpack·程序员