获取当前浏览器大小并设置布局

2021-06-09  本文已影响0人  fanyu__
<template>
    <div class="layout" id="layout" ref="layout" :style="`width:${width}px;height:${height}px`">

    </div>
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
@Component({
    components: {}
})
export default class Layout extends Vue {
    height = 0

    width = 0

    mounted() {
        this.$nextTick(() => {
            this.width = window.innerWidth
            this.height = window.innerHeight
        })

        window.onresize = () => {
            return (() => {
                this.width = window.innerWidth
                this.height = window.innerHeight
            })()
        }
    }
}
</script>

<style lang="scss" scoped>
.layout {
    background: darkcyan;
}
</style>

上一篇下一篇

猜你喜欢

热点阅读