缓存

        //存入缓存
            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()转换为字符串

posted @ 2021-09-28 09:33  从入门到入土  阅读(16)  评论(0编辑  收藏  举报