本来按照事件顺序,小程序初始化时触发App里的onLaunch,后面再执行页面Page里的onLoad,但是在onLaunch里请求获取是否有权限,等待返回值的时候Page里的onLoad事件就已经执行了。
//app.js
App({
onLaunch: function () {
console.log('onLaunch');
wx.request({
url: 'test.php', //仅为示例,并非真实的接口地址
data: {
},
success: function(res) {
console.log('onLaunch-request-success');
// 将employId赋值给全局变量,提供给页面做判断
this.globalData.employId = res.employId;
}
})
},
globalData: {
employId: ''
}
})
//index.js
//获取应用实例
const app = getApp()
Page({
data: {
albumDisabled: true,
bindDisabled: false
},
onLoad: function () {
console.log('onLoad