<template>
<div class="container" :style="{ height: viewportHeight + 'px' }">
<p>当前视口高度: {{ viewportHeight }}px</p>
<!-- 其他内容 -->
</div>
</template>
<script>
export default {
data() {
return {
viewportHeight: 0, // 用于存储视口高度
};
},
mounted() {
this.updateViewportHeight(); // 初始化视口高度
window.addEventListener('resize', this.updateViewportHeight); // 监听窗口大小变化
},
beforeDestroy() {
window.removeEventListener('resize', this.updateViewportHeight); // 移除监听
},
methods: {
updateViewportHeight() {
this.viewportHeight = window.innerHeight; // 获取并更新视口高度
}
}
};
</script>
<style scoped>
.container {
background-color: #f0f0f0; /* 背景色 */
display: flex;
justify-content: center;
align-items: center;
/* 其他样式 */
}
</style>
05-12
5979

08-26
1493

08-09
1139

08-07
3354

04-11
2881

04-13
2852

01-01