Vue 实时获取屏幕宽高


Vue 实时获取屏幕宽高

 

export default { name: 'page-index', data(){ return{ windowWidth: document.documentElement.clientWidth, //实时屏幕宽度
            windowHeight: document.documentElement.clientHeight,   //实时屏幕高度
 } }, methods: { }, // <!--在watch中监听实时宽高-->
 watch: { windowHeight (val) { let that = this; console.log("实时屏幕高度:",val, that.windowHeight ); }, windowWidth (val) { let that = this; console.log("实时屏幕宽度:",val, that.windowHeight ); } }, mounted() { var that = this; // <!--把window.onresize事件挂在到mounted函数上-->
        window.onresize = () => { return (() => { window.fullHeight = document.documentElement.clientHeight; window.fullWidth = document.documentElement.clientWidth; that.windowHeight = window.fullHeight;  //
              that.windowWidth = window.fullWidth; //
 })() }; }, }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM