通过localStorage.getItem('id')
和localStorage.setItem('id',id)
获取存储到的本地数据拿到的是“[object Object]
”形式的数据
解决:
JSON.parse()
和JSON.stringify()
在localStorage.getItem 使用
JSON.stringify
例如
localStorage.setItem('id', JSON.stringify(id))
获取的时候时候使用
JSON.parse()
例如
JSON.parse(localStorage.getItem("id"))
本地在存储时
会默认将Object对象转换成'[Object Object]'字符串