加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vue 监听屏幕高度的实例

发布时间:2020-12-16 23:38:52 所属栏目:百科 来源:网络整理
导读:项目用vue版本是2.0的,项目中用到es6 首先需要在data里面定义页面的高度 把window.onresize事件挂在到mounted div class="jb51code" pre class="brush:js;" mounted() { const that = this window.onresize = () = { return (() = { window.fullHeight = do

项目用vue版本是2.0的,项目中用到es6

首先需要在data里面定义页面的高度

把window.onresize事件挂在到mounted

<div class="jb51code">
<pre class="brush:js;">
mounted() {
const that = this
window.onresize = () => {
return (() => {
window.fullHeight = document.documentElement.clientHeight
that.fullHeight = window.fullHeight
})()
}
}

监听window.onresize事件

这里的定时器是为了优化,如果频繁调用window.onresize方法会造成页面卡顿,增加定时器会避免频繁调用window.onresize方法

以上这篇vue 监听屏幕高度的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程之家。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读