1.创建内容包裹组件(封装公共组件)scale-screen.vue
<!-- 大屏自适应容器组件 -->
<template>
<div class="screen-wrapper" ref="screenWrapper" :style="wrapperStyle">
<slot></slot>
</div>
</template>
<script>
/**
* 防抖函数
*/
function debounce(fn, delay) {
let timer = null
return function (...args) {
timer = setTimeout(
() => {
typeof fn === 'function' && fn.apply(null, args)
clearTimeout(timer)
},
delay > 0 ? delay : 100
)
}
}
export default {
name: 'VScaleScreen',
props: {
width: {
type: [String, Number],
default: 1920
},
height: {
type: [String, Number],
default: 1080
},
fullScreen: {
type: Boolean,
default: false
},
autoScale: {
type: [Object, Boolean],
default: true
},
selfAdaption: {
type: Boolean,
default: true
},
delay: {
type: Number,
default: 500
},
boxStyle: {
type: Object,
default: () => ({})
},
wrapperStyle: {
type: Object,
default: () => ({})
}
},
data() {
return {
currentWidth: 0,
currentHeight: 0,
originalWidth: 0,
originalHeight: 0,
onResize: null,
observer: null
}
},
watch: {
selfAdaption(val) {
if (val) {
this.resize()
this.addListener()
} else {
this.clearListener()
this.clearStyle()
标签:function,default,适配,Object,delay,vue2,大屏,null,type
From: https://blog.csdn.net/web_z/article/details/144957775