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;
		}
    }


Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐