Skip to content

storage 本地存储 ​

  • 不需要JSON.parse ,JSON.Stringify 手动格式化数据
  • 支持ts类型推断

setLocal ​

设置LocalStorage

Parameters:

  • key: - 字符串唯一key
  • content: - 需要存储的内容

Examples:

ts
// localStorage
setLocal('token', '123')

getLocal ​

获取LocalStorage

Parameters:

  • key: - 字符串唯一key

Examples:

ts
const value = getLocal('token')
//支持泛型
const value = getLocal<string>('token')

removeLocal ​

删除指定key的LocalStorage

Parameters:

  • key: - 字符串唯一key

Examples:

ts
const value = removeLocal('token')

setSession ​

设置SessionStorage

Parameters:

  • key: - 字符串唯一key
  • content: - 需要存储的内容

Examples:

ts
// localStorage
setSession('token', '123')

getSession ​

获取SessionStorage

Parameters:

  • key: - 字符串唯一key

Examples:

ts
const value = getSession('token')

removeSession ​

删除指定key的SessionStorage

Parameters:

  • key: - 字符串唯一key

Examples:

ts
const value = removeSession('token')

setStore ​

设置本地存储, 默认type 为localStorage

Parameters:

  • key: - 字符串唯一key
  • value: - 需要存储的内容
  • type: - 存储类型

Examples:

ts
let value = { name: '张三', age: 18 }
// localStorage
setStore('userInfo', value)
// sessionStorage
setStore('userInfo', value, EnumStoreType.SESSION)

getStore ​

获取本地存储, 默认type 为localStorage

Parameters:

  • key: - 字符串key
  • type: - 存储类型

Examples:

ts
// localStorage
const value = getStore('token')
// sessionStorage
const value = getStore('token', EnumStoreType.SESSION)

removeStore ​

删除指定key的Local

Parameters:

  • key: - 字符串key

Examples:

ts
// localStorage
const value = removeStore('token')
// sessionStorage
const value = removeStore('token', EnumStoreType.SESSION)