How does vue use the return value of this function?

what should I do if I want to get the return value of this method? Get the prompt undefined

in this way
  methods: {
    test () {
      console.log(getBrowserInterfaceSize())
    },
    getBrowserInterfaceSize: function () {
      var pageWidth = window.innerWidth
      var pageHeight = window.innerHeight
      if (typeof pageWidth !== "number") {
        if (document.compatMode === "CSS1Compat") {
          pageWidth = document.documentElement.clientWidth
          pageHeight = document.documentElement.clientHeight
        } else {
          pageWidth = document.body.clientWidth
          pageHeight = window.body.clientHeight
        }
      }
      return {
        pageWidth: pageWidth,
        pageHeight: pageHeight
      }
    }
  }
Jun.04,2021

methods: {
    test () {
      console.log(this.getBrowserInterfaceSize())
    },
    getBrowserInterfaceSize: function () {
        //...
    }
  }

just add a this.


but try to back up the this:

var that = this;
that. * *

Menu