<div class="bg"
:style="{'height':windowHeight+'px'}">
pc端页面
</div>
data () {
return {
windowHeight: window.innerHeight
}
}
mounted () {
window.onresize = () => {
this.windowHeight = window.innerHeight
}
}
watch: {
'windowHeight': function (newVal, oldVal) { //监听屏幕宽度变化
this.windowHeight = newVal
console.log(newVal)
}
}
VUE监听resize
于 2020-12-22 13:38:00 首次发布
本文介绍了一个使用Vue.js实现的简单自适应高度的DIV组件案例。该组件能够根据浏览器窗口大小的变化调整自身的高度,并通过监听窗口尺寸变化来实时更新高度值。

5万+

被折叠的 条评论
为什么被折叠?



