//logs.js // const util = require('../../utils/util.js') const app = require('../../utils/util.js'); Page({ data: { dataArr: [] }, gomyClass() { wx.switchTab({ url: '../myClass/myClass' }) }, getArr(sessionKey) { var _this = this; wx.request({ url: app.globalData.publicUrl2 + '/wx/student/selWholeClas', method: "post", data:{ sessionKey:sessionKey }, success: function (res) { console.log(res.data.data, "22222") _this.setData({ dataArr: res.data.data }) } }) }, onLoad: function () { // var _this = this; wx.checkSession({ success: () => { var sessionKey = wx.getStorageSync('sessionKey'); if (sessionKey == "") { wx.login({ success(res) { console.log(res); var code = res.code wx.request({ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', method: "get", data: { code }, success: function (res) { sessionKey = res.data.sessionKey; wx.setStorageSync('sessionKey', res.data.sessionKey); this.getArr(sessionKey); } }) } }) } else { this.getArr(sessionKey); } }, fail() { console.log("我没有缓存并去登录请求") wx.login({ success(res) { var code = res.code wx.request({ url: app.globalData.publicUrl2 + '/wx/user/wx7e7a46e129d6cd0f/login', method: "get", data: { code }, success: function (res) { wx.setStorageSync('sessionKey', res.data.sessionKey); var sessionKey = res.data.sessionKey this.getArr(sessionKey); } }) } }) } }) } })