从 localStorage 读取值 对象通过 JSON.parse 反序列化,基础类型以字符串返回
localStorage
JSON.parse
存储键
key 不存在或数据不可读时返回,默认为 ''
''
反序列化后的值,或 def
def
const token = getStorage('token') // 'abc123'const user = getStorage('user') // { name: 'Alice', age: 30 }const val = getStorage('missing', 'default') // 'default' Copy
const token = getStorage('token') // 'abc123'const user = getStorage('user') // { name: 'Alice', age: 30 }const val = getStorage('missing', 'default') // 'default'
从
localStorage读取值 对象通过JSON.parse反序列化,基础类型以字符串返回