-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
43 lines (42 loc) · 1.08 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//app.js
import User from "./models/user";
App({
onLaunch: async function () {
// 登录
this.getUser()
},
// 监听uid属性
watch: function (method) {
let obj = this.globalData;
Object.defineProperty(obj, "uid", {
configurable: true,
enumerable: true,
set: function (value) {
this._uid = value;
method(obj.user);
},
get: function () {
return this._uid
}
})
},
getUser: async function() {
let obj = this;
const user = await User.getUser().then(null, (e) => {
wx.showModal({
title: '加载用户信息失败',
showCancel: false,//是否显示取消按钮
confirmText: '重试',
success() {
obj.getUser()
}
})
})
this.globalData.user = user.data
this.globalData.uid = user.data.id
},
globalData: {
userInfo: null,
user: {}
},
})