Uncaught (in promise) ReferenceError: userInfo is not defined
问题描述:
在完成登录后,用vuex存储用户信息,保存用户登录信息,到了首页之后想要读取信息继而显示登录名,但是将方法移到首页并且在data里注册,还是一直报错。
解决方法:
后面经过我的尝试发现,我少了个返回值,加了个return便可以了
export default{
data(){
return{
uInfs:{},
names:''
}
},
mounted(){
this.getUDatas();
},
methods:{
goSearch(event){
this.$router.push('/search');
window.event? window.event.returnValue = false : event.preventDefault();
},
getUDatas(){
let _this = this;
let uObj ={};
let names='';
if(window.sessionStorage.userInfo){
let uObj = JSON.parse(window.sessionStorage.userInfo);
let useId = uObj.user_id;
_this.$http.get('/userinfo',{
params:{
uId:useId
}
}).then((res)=>{
_this.uInfs = res.data;
_this.names = _this.uInfs.user_name;
},(err)=>{
console.log(err);
});
}
return names;
}
}