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>
相关推荐
子兮曰4 天前
jev-ultrafast 深度解析:7 秒订机票的浏览器 Agent 是如何炼成的
前端·后端·agent
子兮曰4 天前
Jev 爆发一周:7 秒 Agent 背后的 System One 生态与三场争议
前端·后端·ai编程
前端小万4 天前
写公众号赚了 3000 块后,我做了一款叫 "一键成稿" 的软件
前端·微信小程序
爱勇宝4 天前
ZCode 开源 24 小时:一份没有历史的账本,回答不了"有没有偷代码"
前端·后端·chatglm (智谱)
A黄俊辉A4 天前
uniapp webview中实现 app和内嵌的H5双向通信
vue.js·json
三十而立洋4 天前
Cookie 详解:从产生到安全,一次讲透
前端·javascript
卡布鲁4 天前
把一个 Vite + Vue3 应用塞进 qiankun (React + Umi3) 主站:十个坑的复盘
前端·javascript·react.js
李少兄4 天前
JavaScript 隐式全局变量解析
javascript
honkun64 天前
vue 表格组件 vxe-table 配置 ajax 请求自动加载数据与表单查询
vue.js·vxe-table
kybs19914 天前
全球灾害数据分析可视化 毕业设计-附源码66794
vue.js·spring boot·mysql·安全·django·c#·asp.net