Vue monitors browser window changes

mounted() {
  window.onresize = () => {
    return (() => {
      this.$nextTick(() => {
        console.log('clientWidth', document.body.clientWidth);
        console.log('clientHeight', document.body.clientHeight)
      })
    })()
  }
},

Note: It is possible to monitor
in createdand , but if you monitor in created, the document has not been generated at this time. Please implement it according to your actual needs. Adding mountedis also to ensure that the DOM has been loaded at this time.$nextTick()

Guess you like

Origin blog.csdn.net/qq_29483485/article/details/129958840