国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

Vue 實時監聽窗口變化 windowresize的兩種方法

2024-05-06 15:28:10
字體:
來源:轉載
供稿:網友

下面給大家分享兩種方法來介紹Vue 實時監聽窗口變化 windowresize,具體內容如下所示:

方法一:

First-step : 定義變量

data(){  return{     formLabelWidth : '123px'  }},

Second-step:   根據生命周期 在mounted 中綁定 窗口變化

 mounted(){       const that = this       window.onresize = () => {         return (() => {          window.screenWidth = document.body.clientWidth          that.screenWidth = window.screenWidth         })()       } },

Third-step:   綁定監聽 watch

watch: {       screenWidth (val) {            if (!this.timer) {              this.screenWidth = val              this.timer = true              let that = this              setTimeout(function () {                // that.screenWidth = that.$store.state.canvasWidth                console.log(that.screenWidth)                // that.init()                that.timer = false              }, 400)            }       } },

方法二:在vue.2x里面時候,mounted 里面可以直接掛載 window.onresize事件。全局監聽

 mounted(){       window.onresize = () => {         return (() => {           this.handleLableWidth();         })()       }       this.handleLableWidth();},

完全可以做到檢測窗口變化

總結

以上所述是小編給大家介紹的Vue 實時監聽窗口變化 windowresize的兩種方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對錯新站長站網站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 正定县| 招远市| 达日县| 临沧市| 铜陵市| 富宁县| 石首市| 盐山县| 东乌珠穆沁旗| 郓城县| 建始县| 通化市| 招远市| 武川县| 德令哈市| 驻马店市| 平和县| 堆龙德庆县| 酒泉市| 新郑市| 姚安县| 和林格尔县| 安顺市| 贵州省| 馆陶县| 万全县| 漠河县| 开鲁县| 会理县| 中山市| 济南市| 阿鲁科尔沁旗| 郓城县| 锡林郭勒盟| 瑞金市| 吴忠市| 青海省| 扬中市| 衢州市| 罗山县| 日土县|