收藏
回答

无法访问全局变量globalData, 如何解决?

这是在app.js里设置的全局变量数据结构, 但是我在其它js文件里调用的时候报错:

回答关注问题邀请回答
收藏

5 个回答

  • 花漂漂
    花漂漂
    2022-10-02

    解决了吗

    2022-10-02
    有用
    回复
  • Mr.sòng
    Mr.sòng
    2021-05-24
    const app = getApp();
    const userInfo = app.globalData.userInfo;
    


    2021-05-24
    有用
    回复
  • destiny
    destiny
    2021-05-24

    globalData里面就没有定义userInfo,

    const userInfo = getApp().globalData.userInfo;

    用wx.getUserProfile获取用户信息

    2021-05-24
    有用
    回复 4
    • Eugene
      Eugene
      2021-05-24
      仍然不行诶... const userInfo = getApp().globalData.userInfo;这条报错了:
      TypeError: Cannot read property 'userInfo' of undefined
      2021-05-24
      回复
    • destiny
      destiny
      2021-05-24回复Eugene
      都说了你没有定义啊
       globalData: {userInfo:{}}
      2021-05-24
      回复
    • Eugene
      Eugene
      2021-05-24回复destiny
      定义了的...
      2021-05-24
      回复
    • destiny
      destiny
      2021-05-24回复Eugene
      ......   console.log和debugger了解一下
      2021-05-24
      回复
  • 那个谁
    那个谁
    2021-05-24
    const app = getApp();
    const userInfo = app.globalData.userInfo;
    
    2021-05-24
    有用
    回复
  • chh
    chh
    2021-05-24

    发出来看看怎么调用的

    2021-05-24
    有用
    回复 3
    • Eugene
      Eugene
      2021-05-24
      2021-05-24
      回复
    • Eugene
      Eugene
      2021-05-24
      2021-05-24
      回复
    • Eugene
      Eugene
      2021-05-24回复Eugene
      我靠   代码下半截丢失了   我重新传一下
      2021-05-24
      回复
登录 后发表内容