zoukankan      html  css  js  c++  java
  • 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; //
                })()
              };
        },
    }
  • 相关阅读:
    数据库基本概念(一)
    Java语言概述
    Linx
    小菜鸟之Cisco
    小菜鸟之网络基础1
    小菜鸟之JAVA输入输出
    小菜鸟之java JDBC编程
    小菜鸟之JAVA面试题库1
    小菜鸟之java异常
    小菜鸟之正则表达式
  • 原文地址:https://www.cnblogs.com/sanyekui/p/12745152.html
Copyright © 2011-2022 走看看