The initialization values of other pages of Mini Program project are in two states.

app.js file

< hr >
 onLaunch: function () {
    console.log("app-onLaunch")
    this.getUserInfo();
   
  },
  onShow:function(){
    console.log("app-onShow")
  },
  // 

  getUserInfo: function (callBack) {
    let that = this;
    if (this.globalData.userInfo) {
      typeof cb == "function" && cb(this.globalData.userInfo)
    } else {
      wx.login({
        success: function (res1) {
          console.log("res11111111111111111",res1);
          if (res1.code) {
            //
            wx.getUserInfo({
              success: res => {
                //  res  unionId
                //console.log("ryy-getUserInfo", res.userInfo)
                that.globalData.userInfo = res.userInfo

                wx.request({
                  url: that.config.HOST + "/user/userLogin.do",
                  data: {
                    code: res1.code, //openid
                    headimgurl: res.userInfo.avatarUrl,
                    nickname: res.userInfo.nickName,
                    city: res.userInfo.city,
                    appid: that.globalData.AppId,
                    province: res.userInfo.province,
                    shop_id: "10001",
                  },
                  header: {
                    "content-type": "application/json"
                  },
                  success: function (res) {
                    console.log("tets1", res)
                    if (res && res.statusCode == 200) {
                      wx.setStorageSync("session_id", res.data.data.session_id)
                      that.globalData.header.Cookie = "JSESSIONID=" + res.data.data.session_id;
                      that.globalData.is_vip = res.data.data.is_vip;
                      console.log("that.globalData-------------------PPPPPPPPPPPPPPPPPPPP", that.globalData)
                      //console.log("that.globalData.header", that.globalData.header.Cookie)
                      //console.log("ryy-qest" + JSON.stringify(res.data), res.data.data)
                      //login
                      if (callBack) {
                        callBack()
                      }
                    
                    }

                  }
                })
              },
 globalData: {
    userInfo: null,
    openid:null,
    user_id:null,
    code:null,
    header:{Cookie:null},
    session_id:null,
    img_domain:null,
    telephone:null,
    is_vip:null,
    getInit:{},
  },

index.js pages under other page files

< hr >

clipboard.png
does not print cookie, in onload or other lifecycles: one is null, the other is valuable
. An exclamation point appears next to: Value below was evaluated just now
, but if you print, console.log (app.globalData.header.Cookie) shows null

.

but you can get the value of cookie by clicking on the verification code in the custom method.
I really don"t know how to solve this problem. I hope to be Mini Program for the first time. I hope someone can give me some advice

.

it is estimated that the whole world is not stored. It should be asynchronous. I have encountered it before because async has not been assigned successfully, so I use it. For the sake of aspect, you can add a delay timer to try


I would like to ask, have you solved

Menu