页面自适应

<template>
  <div id="app">

    <div _tmplitem="56" class="dv-full-screen-container" :style="css">
      <div _tmplitem="56" style="position: absolute;width:1920px;height:1080px;  background-size: contain;"
           class="div-full-screen">
        <router-view/>
        <theme-picker/>
      </div>
    </div>
  </div>
</template>

<script>
import ThemePicker from "@/components/ThemePicker";

export default {
  name: "App",
  data() {
    return {
      css: '',
    }

  },
  components: {ThemePicker},
  metaInfo() {
    return {
      title: this.$store.state.settings.dynamicTitle && this.$store.state.settings.title,
      titleTemplate: title => {
        return title ? `${title} - ${process.env.VUE_APP_TITLE}` : process.env.VUE_APP_TITLE
      }
    }
  }
  , methods: {
    created_sys() {
      let $this = this;
      this.w = this.w === undefined ? 1920 : this.w;
      this.h = this.h === undefined ? 1080 : this.h; // 设置默认高度为 1080,可以根据实际情况修改

      $this.css = `width: ${$this.w}px; height: ${$this.h}px; ${$this.bg === "" ? "" : "background-image:url(" + $this.bg + "); background-size: contain;"} transform: scale(${document.body.clientWidth / $this.w}, ${document.body.clientHeight / $this.h}); ${$this.bgColor === "" ? "" : "background-color:" + $this.bgColor + "; left:calc( 50% - " + $this.w / 2 + "px);"}`

      window.addEventListener("resize", () => {
        $this.css = `width: ${$this.w}px; height: ${$this.h}px; ${$this.bg === "" ? "" : "background-image:url(" + $this.bg + "); background-size: contain;"} transform: scale(${document.body.clientWidth / $this.w}, ${document.body.clientHeight / $this.h}); ${$this.bgColor === "" ? "" : "background-color:" + $this.bgColor + ";"}`
      });

      $this.css = `transform: scale(${document.body.clientWidth / $this.w}, ${document.body.clientHeight / $this.h})`;

    },

  },
  created() {
    this.created_sys();

  }
};
</script>
<style scoped>
.dv-full-screen-container {
  transform: scale(1);
  position: absolute;
  top: 0px;
  left: 0px;
  overflow: hidden;
  transform-origin: left top;
  z-index: 499;
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  width: 1920px;
  height: 1080px;
  background-size: cover;
  background-repeat: no-repeat;
}

#app .theme-picker {
  display: none;
}
</style>
  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值