html52.com
我爱小程序-开发者交流社区

app.globalData为什么获取不到数据而且输出的是undefined还报错?

打印app是ve {onLaunch: ƒ, onShow: ƒ, onHide: ƒ, onUnlaunch: ƒ}

打印app是ve {onLaunch: ƒ, onShow: ƒ, onHide: ƒ, onUnlaunch: ƒ}而且代码全部是对的

而且代码全部是对的

而且代码全部是对的onLoad: function () {
    console.log(app)
    if (app.globalData.user

onLoad: function () {
    console.log(app)
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        //hasUserInfo: true
      })
    } else if (this.data.canIUse){
      // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
      // 所以此处加入 callback 以防止这种情况
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          //hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        successres => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            //hasUserInfo: true
          })
        }
      })
    }
  },


  getUserInfofunction(e{
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    console.log(e.detail.userInfo)
    if(e.detail.userInfo){
      wx.login({
        success(res) => {
          console.log(res.code)
          //获取openid
          wx.request({
            url: app.globalData.webJavaserver+'wxlogin/login?code=&nickname=' + e.detail.userInfo.nickName,
            header:{
              "content-type""application/json"
            },
            success(res){
              //保存userId
              app.globalData.openid = rea.data;
              console.log(app.globalData.openid)
              //路由跳转
              wx.switchTab({
                url'/pages/index/index',
              })
            }
          })
          
        },
      })
    }else{
      wx.showModal({
        title'提示',
        content"你将无法正常使用"
      })
    }
    this.setData({
      userInfo: e.detail.userInfo,
      //hasUserInfo: true
    })
  },
请问有大神知道是怎么肥事吗?
w我终于直到怎么回事了,emmmm...我把文件一个一个复制过去,然后发现有一个js页面写成了const app = new App(),
z找了一下午一晚上啊啊啊啊,应该写成const app = getApp(),所有页面都是,这样才能获取到数据,我真的。。。太难了

网友回复

Jnimy:

顶一下,虽然不知道有没有用

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付