// app.js App({ onLaunch() { // 登录 wx.login({ success: res => { // 发送 res.code 到后台换取 openId, sessionKey, unionId } }) }, routeSafer(hasUserInfo){ hasUserInfo=this.globalData.hasUserInfo if (hasUserInfo != true) { wx.showToast({ title: '请先登录!', icon:'error', duration:1000, success(){ setTimeout(() => { wx.redirectTo({ url: '/pages/index/index', }) }, 1000); } }) } }, globalData: { userInfo:{}, hasUserInfo:false } })