Appearance
storage
• storage: Object
本地存储相关办法,支持设置过期时间
Type declaration
Name | Type |
---|---|
getItem | (key : string | string []) => any |
removeItem | (key : string | string []) => void |
setItem | (key : string | string [], data : Record <string , any >) => void |
getItem: (key
: string
| string
[]) => any
从本地缓存中同步获取指定 key 对应的内容
Throws
- 如果未提供有效的 key,将抛出错误
示例
ts
const value = storage.getItem('key')
removeItem: (key
: string
| string
[]) => void
从本地缓存中同步移除指定 key
Throws
- 如果未提供有效的 key,将抛出错误
示例
ts
storage.removeItem('key')
setItem: (key
: string
| string
[], data
: Record
<string
, any
>) => void
设置本地缓存中指定 key 的数据
Throws
- 如果未提供有效的 key,将抛出错误
示例
ts
storage.setItem('key', {value: 1})