Local Storage中的数据只要不是人为原因一般不会被清除,Session Storage中的数据将会话结束后就会被清除

将数据存入Local Storage中:


//定义一个数组
 const obj = [{
             id: state.nextId,
             info: state.inputValue.trim(),
             done: false
        }]
//将数组obj转换成json格式后存储到Local Storage中,并命名为accessToken
localStorage.setItem('accessToken',JSON.stringify(obj) )

//删除Local Storage中的accessToken
localStorage.removeItem('accessToken')
//取出accessToken并还原
JSON.parse(localStorage.getItem("accessToken"))

将数据存入Session Storage中:

//待更新
微信扫一扫体验微信小程序
Last modification:September 21, 2022
If you think my article is useful to you, please feel free to appreciate