场景:微信小程序首页页面渲染快,wx.login执行慢,导致首页中变量不是最新的
app.js
watch: function (method) {
var obj = this.globalData
Object.defineProperty(obj, 'IsAuthorization', {
configurable: true,
enumerable: true,
set: function (value) {
this._name = value;
method(value);
},
get: function(){
return this._name
}
})
},
globalData: {
userInfo: null,
openid: '', // openid
wx_token: '', // wx_token
IsAuthorization: false, // 是否绑定(是否授权)
}
index.js
onLoad:function(options){
let that = this;
getApp().watch(that.watchBack)
},
watchBack: function (value){
this.setData({
IsAuthorization: value
})
},