完成用户登录和全局token
This commit is contained in:
@@ -1,13 +1,38 @@
|
||||
import Toast from 'tdesign-miniprogram/toast/index';
|
||||
Component({
|
||||
data: {
|
||||
img1: 'https://tdesign.gtimg.com/mobile/demos/example1.png',
|
||||
img2: 'https://tdesign.gtimg.com/mobile/demos/example2.png',
|
||||
img3: 'https://tdesign.gtimg.com/mobile/demos/example3.png',
|
||||
image: 'https://tdesign.gtimg.com/mobile/demos/avatar1.png',
|
||||
hasToken: false,
|
||||
username: ''
|
||||
},
|
||||
methods: {
|
||||
userlogin(){
|
||||
wx.navigateTo({url:'/pages/user-login/user-login'})
|
||||
}
|
||||
},
|
||||
refreshUserStatus(){
|
||||
console.log("主动刷新user界面")
|
||||
const app = getApp();
|
||||
console.log("全局userinfo",app.globalData.userInfo)
|
||||
console.log("全局用户信息:", app.globalData.userInfo.username); // 这里打印的是 userInfo
|
||||
const userInfo = app.globalData.userInfo || {};
|
||||
console.log("user中的userInfo:",userInfo)
|
||||
this.setData({
|
||||
hasToken: !!app.globalData.token, // 从全局变量获取token状态
|
||||
username: userInfo.username
|
||||
});
|
||||
// 调试:确认页面数据是否正确
|
||||
console.log("页面username赋值后:", this.data.username);
|
||||
},
|
||||
|
||||
},
|
||||
lifetimes:{
|
||||
attached(){
|
||||
console.log("user界面刷新")
|
||||
this.refreshUserStatus()
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user