记录—Vue实时获取页面宽高

Vue实时获取页面宽高


export default {
    name: 'page-index',
    data(){
        return{
            windowWidth: document.documentElement.clientWidth,  //实时屏幕宽度
            windowHeight: document.documentElement.clientHeight,   //实时屏幕高度
        }
    },    
    methods: {
    },
    // 
    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 = () => {
            return (() => {
              window.fullHeight = document.documentElement.clientHeight;
                window.fullWidth = document.documentElement.clientWidth;
              that.windowHeight = window.fullHeight;  // 高
              that.windowWidth = window.fullWidth; // 宽
            })()
          };
    },
}

你可能感兴趣的:(记录—Vue实时获取页面宽高)