欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue 監(jiān)聽屏幕高度的實(shí)例

 更新時(shí)間:2018年09月05日 09:20:01   作者:bai_riqiang  
今天小編就為大家分享一篇vue 監(jiān)聽屏幕高度的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧

項(xiàng)目用vue版本是2.0的,項(xiàng)目中用到es6

首先需要在data里面定義頁(yè)面的高度

data (){
  return {
    fullHeight: document.documentElement.clientHeight
  }
}

把window.onresize事件掛在到mounted

mounted() {
   const that = this
   window.onresize = () => {
    return (() => {
     window.fullHeight = document.documentElement.clientHeight
     that.fullHeight = window.fullHeight
    })()
   }
  }

監(jiān)聽window.onresize事件

 watch: {
   fullHeight (val) {
    if(!this.timer) {
     this.fullHeight = val
     this.timer = true
     let that = this
     setTimeout(function (){
      that.timer = false
     },400)
    }
   }
  }

這里的定時(shí)器是為了優(yōu)化,如果頻繁調(diào)用window.onresize方法會(huì)造成頁(yè)面卡頓,增加定時(shí)器會(huì)避免頻繁調(diào)用window.onresize方法

以上這篇vue 監(jiān)聽屏幕高度的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論