小程序token回调问题

App({
  onLaunch: function(options) {
  },

  wxLogin() { 
    let that = this;
    return new Promise((resolve, reject) => {
      wx.request({
        url: 'www.xx.com',
        success: function(res) {
           that.globalData.web_name = '222'
           resolve(res.data)
        }
      })
    })
  }, 
  globalData: {
    web_name: '111'
  }
})

 

//index.js
const app = getApp()
Page({
  data: {
  },
  onLoad(){ 
     console.log('first:', app.globalData.web_name)     //111
     app.wxLogin().then(res => {      
       console.log('second:', app.globalData.web_name) //222
    });
     console.log('third:', app.globalData.web_name)     //111
  }
})




posted @ 2020-07-24 12:02  blogs-[字母控]  阅读(210)  评论(0编辑  收藏  举报