缓存
//存入缓存 localStorage.setItem("dataList",JSON.stringify(res))
//判断是否有缓存 haveLocalStorage(key){ if(localStorage.getItem(key)){ this.isLogin = true return true }else{ return false } },
//取出缓存 if(this.haveLocalStorage("dataList")){ // 存储 this.dataList = JSON.parse(localStorage.getItem("dataList")) this.nickname = this.dataList.data.userInfo.nickname this.avatarUrl = this.dataList.data.userInfo.avatarUrl }
//清除所有缓存 localStorage.clear();
sessionStorage.removeItem("a");清除指定缓存
JSON.parse()转换成JSON对象
JSON.stringify()转换为字符串