Skip to content

关于app.js isLogin异步的问题 #1

@15560099568

Description

@15560099568
wxGetSetting().then(res => {
      if (res.authSetting['scope.userInfo']) {
        wxGetUserInfo().then(res => {
          that.globalData.nickName = res.userInfo.nickName;
          that.globalData.userAvatar = res.userInfo.avatarUrl;
          // 确认所需全局变量正常 否则重新登录获取
          if (isAllStorageOk) {
            that.globalData.isLogin = true;
          }
          if (that.globalData.uid != "") {
            // put 更新用户信息
            let url = `${that.globalData.commonUrl}/user/${that.globalData.uid}`
            let data = res.userInfo;
            let header = {
              "content-type": "application/x-www-form-urlencoded",
              "Authorization": `Bearer ${that.globalData.token}`
            };
            requestUtils.doPUT(url, data, header).catch(res => {
              console.log("更新用户数据失败");
              console.log(res);
            });
          }
        });
      }

app.js里设置that.globalData.isLogin = true是异步操作,如果首次打开在个人页面的话,isLogin在页面onShow是false的。没有及时更新

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions