// index.js const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0' const app=getApp() Page({ data: { userInfo: { avatarUrl: defaultAvatarUrl, nickName: '', }, userName: '', }, onChooseAvatar(e) { const { avatarUrl } = e.detail this.setData({ userInfo: { avatarUrl }, }) }, iptHandler(e) { const nickName = e.detail.value this.setData({ // 通过e.detail.value获取到文本框最新的值 userName: nickName, }) }, onLogin() { if (this.data.userInfo.avatarUrl != defaultAvatarUrl && this.data.userName != '') { wx.clearStorageSync('userInfo') var userInfo = { avatarUrl: '', nickName: '' } userInfo.avatarUrl = this.data.userInfo.avatarUrl userInfo.nickName = this.data.userName wx.showToast({ title: '登录中', icon: "loading", duration: 800, complete() { app.globalData.userInfo=userInfo app.globalData.hasUserInfo=true; wx.switchTab({ url: '/pages/intro/intro' }) } }); } else { wx.showToast({ title: '请输入用户头像及昵称', icon: "error", duration: 2000 }); } } })