当前位置: 代码迷 >> 综合 >> Cannot read property 'globalData' of undefined;at App onLaunch function
  详细解决方案

Cannot read property 'globalData' of undefined;at App onLaunch function

热度:88   发布时间:2024-01-18 03:50:44.0

Cannot read property 'globalData' of undefined;at App onLaunch function

最初是将 'globalData'  的定义放在了 app.js 最后面,认为是还没有加载;然后把定义放在 onLaunch 前面,但还是不行;所以认为是在 App 的 onLaunch 事件处理程序中无法读取globalData,因为其还没有被加载定义;

后来发现是 this 变量的作用域问题,在函数的一开始就定义一个变量指向this,

let that = this;

 

 

需要使用的时候调用这个新定义的变量就可以了。

  相关解决方案