# getApp()

The getApp() function is used to obtain the current application instance, generally used to obtain globalData.

Instance

const app = getApp()
console.log(app.globalData) 

Notice:

  • Do not call getApp() in a function defined in App() or before calling App, you can get the corresponding app instance through this.$scope
  • After obtaining the instance through getApp(), do not call the life cycle function privately.
  • When you use getApp() in the home page nvue, you may not necessarily get the real App object. For this reason, const app = getApp({allowDefault: true}) is provided to obtain the original App object, which can be used to initialize globalData etc. on the homepage
On This Page