forked from ThanatosXX/flea-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
47 lines (45 loc) · 1.42 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
44
45
46
47
App({
currentPage: null,
onLaunch: function () {
let userInfo = wx.getStorageSync('userInfo');
this.setGlobalData({
userInfo: userInfo,
is_login: userInfo?true:false,
imgs: '../../image/defaultImg.png',
imgs1: '../../image/defaultImg.png',
imgs2: '../../image/defaultImg.png',
upload_imgs: [
'','',''
]
})
wx.getStorage({
key: 'is_bind',
success: function(res) {
if(!res.data){
wx.setStorageSync('is_bind', false)
}
},
fail: function(res){
wx.setStorageSync('is_bind', false)
}
})
},
globalData: {},
//如果某个页面要使用全局数据的话,必须在onlaod里调用这个函数
//这样在每次setGlobalData之后会自动将数据同步到对应页面的data
//参数就是this
bindPage: function(page){
page.setData(this.globalData);
this.currentPage = page;
},
//用法同setData
//每次调用后都会引起页面重新渲染
setGlobalData: function(data){
Object.keys(data).forEach(key=>{
this.globalData[key] = data[key];
});
if(this.currentPage !== null){
this.currentPage.setData(data);
}
}
})