前端代码
created(){
localStorage.setItem("user.user",user);
},
第二页面
created(){
var params={"student_number":localStorage.getItem("user.user")};
axios.post("/apartment2019/findWeijiByStudent_number",params).then((res)=>{
this.student1=res.data.list;
});
},
运行之后显示student_number不识别,我该怎么把这个用户名保存在local storage中并在下一页面获取。
localStorage 存储只能是 String 格式,如果要存储对象 请 转成string ... ...
localStorage 只能存储 string 格式的,需要转换下:
存 localStorage.setItem("user.user",JSON.stringify(user));
取 let data = JSON.parse(localStorage.getItem("user.user"));