Vue开发页面时自动匹配页面大小宽度的方法

方法写在 watch 当中,因为要监听 initData 中的数据变化 

watch: {
      initData () {
        let H = document.querySelector('.boxShadow')
        H.style.height = ''
        setTimeout(() => {
          console.log(H.offsetHeight)
          if (H.offsetHeight < window.innerHeight) {
            document.body.style.height = window.innerHeight + 'px'
            H.style.height = window.innerHeight - 30 + 'px'
          } else {
            document.body.style.height = H.offsetHeight + 'px'
            H.style.height = ''
          }
        }, 300)
      }
    }

 boxShadow 为定义的类的

 

你可能感兴趣的:(Vue开发页面时自动匹配页面大小宽度的方法)