<template>
<div class="scale-box">
<slot></slot>
</div>
</template>
<script setup>
import { ref, onMounted, defineProps } from "vue";
const width = ref(null), //设计宽度
height = ref(null), //设计高度
scale = ref(null);
const props = defineProps({
width: {
type: String,
default: "1920",
},
height: {
type: String,
default: "1080",
},
});
const init = () => {
setScale();
window.addEventListener("resize", setScale);
};
const setScale = () => {
let ww = document.documentElement.clientWidth / props.width;
let wh = document.documentElement.clientHeight / props.height;
scale.value = ww < wh ? ww : wh;
};
init();
</script>
<style scoped lang="scss">
.scale-box {
width:1920px;
height: 1080px;
transform: scale(v-bind(scale)) translate(-50%, -50%);
transform-origin: 0 0;
position: absolute;
left: 50%;
top: 50%;
transition: 0.3s;
}
</style>
数据大屏自适应方法
于 2023-02-21 13:34:27 首次发布