获取showLoginDialog可以获取的到,但是换成userifno的时候无法获取了
const util = require('../../../utils/util.js');
const api = require('../../../config/api.js');
const user = require('../../../services/user.js');
const app = getApp();
Page({
data: {
userInfo: {
},
showLoginDialog: false
},
onLoad: function(options) {
// 页面初始化 options为页面跳转所带来的参数
},
onReady: function() {
},
onShow: function() {
console.log(this.data.userInfo)
this.setData({
userInfo: app.globalData.userInfo,
});
console.log(this.data.userInfo.nickName)
},
onHide: function() {
// 页面隐藏
},
onUnload: function() {
// 页面关闭
},
onUserInfoClick: function() {
if (wx.getStorageSync('token')) {
} else {
this.showLoginDialog();
}
},
showLoginDialog() {
this.setData({
showLoginDialog: true
})
},
onCloseLoginDialog () {
this.setData({
showLoginDialog: false
})
},
onDialogBody () {
// 阻止冒泡
},
onWechatLogin(e) {
if (e.detail.errMsg !== 'getUserInfo:ok') {
if (e.detail.errMsg === 'getUserInfo:fail auth deny') {
return false
}
wx.showToast({
title: '微信登录失败',
})
return false
}
util.login().then((res) => {
return util.request(api.AuthLoginByWeixin, {
code: res,
userInfo: e.detail
}, 'POST');
}).then((res) => {
console.log(res)
if (res.errno !== 0) {
wx.showToast({
title: '微信登录失败',
})
return false;
}
// 设置用户信息
this.setData({
userInfo: res.data.userInfo,
showLoginDialog: false
});
app.globalData.userInfo = res.data.userInfo;
this.setData({
userInfo: app.globalData.userInfo,
});
console.log(app.globalData.userInfo)
app.globalData.token = res.data.token;
wx.setStorageSync('userInfo', JSON.stringify(res.data.userInfo));
wx.setStorageSync('token', res.data.token);
}).catch((err) => {
console.log(err)
})
},
onOrderInfoClick: function(event) {
wx.navigateTo({
url: '/pages/ucenter/order/order',
})
},
onSectionItemClick: function(event) {
},
// TODO 移到个人信息页面
exitLogin: function() {
wx.showModal({
title: '',
confirmColor: '#b4282d',
content: '退出登录?',
success: function(res) {
if (res.confirm) {
wx.removeStorageSync('token');
wx.removeStorageSync('userInfo');
wx.switchTab({
url: '/pages/index/index'
});
}
}
})
}
})
这是js代码。控制台打印appdata中的userifno可以显示出来,就是在wxml获取的的时候获取不出来,这是为什么,有大神能帮忙解决一下吗

你都不区分大小写啊 这么马虎
userInfo是一个对象啊,需要渲染肯定得指定下面的某一个值啊,showLoginDialog是个独立的布尔类型所以能渲染啊,
userInfo 是个对象,取属性要通过 userInfo.属性名的方式
你要展示啥?应该是{{userInfo.nickName}}