小程序token回调问题

时间:2020-07-24 15:36:17   收藏:0   阅读:101
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
  }
})




评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!