例如,如何恢复存储在us_firstname
中的对象的LocalStorage
?
studentInfos() {
this.eleveService.apiGetEleveInfo(this.token, this.us_id)
.subscribe((data: any) => {
this.student = data.results[0]
localStorage.setItem("student", JSON.stringify(data));
console.log('student', this.student)
})
}
答案 0 :(得分:1)
const student = JSON.parse(localstorage.getItem(“ student”))[0]
答案 1 :(得分:0)
您可以使用以下方法获取本地存储值:
getItem()方法返回指定存储对象项的值。
let student = localStorage.getItem("student");
// convert this to object
student = JSON.parse(student);