Page({ data: { userInfo: null, }, // 登录 goLogin() { my.navigateTo({ url: '/pages/login/index', }) }, // 用户信息 handeleGetInfo() { let userInfo = my.getStorageSync({ key: "userInfo" }); this.setData({ userInfo: userInfo.data }) }, // 退出登录 async loginOut() { let that = this; my.showToast({ type: 'none', content: "操作成功", duration: 800, mask: true, success: function () { setTimeout(function () { that.setData({ userInfo: null }); my.removeStorageSync({ key: 'userInfo' }); // 清除所有缓存数据 my.clearStorageSync(); my.navigateTo({ url: '/pages/login/index', }) }, 800); } }); }, // 头像预览 preview(event) { let currentUrl = event.currentTarget.dataset.src wx.previewImage({ current: currentUrl, // 当前显示图片的http链接 urls: [currentUrl] // 需要预览的图片http链接列表 }) }, onLoad() { }, onShow() { this.handeleGetInfo() }, });