Skip to content

Latest commit

 

History

History
46 lines (39 loc) · 1.11 KB

storage.md

File metadata and controls

46 lines (39 loc) · 1.11 KB

useStorage

为【storage】提供过期时间,get,set等函数

Type

type useStorageOption = {
    keyBase?: string
    expires?: number
}
function useStorage(storage: Storage, option?: useStorageOption): {
    get(key: string): any
    set(key: string, value: any, expi?: number): void
    remove(key: string): void
}

Params

  • storage — 供使用的storage(WindowLocalStorage或WindowSessionStorage)
  • option — storage使用参数
    • keyBase — storage中存储键的前缀,防止重复添加
    • expires — storage中存储的默认过期时间,单位为秒,默认为0

Return

  • get(key) — 获取某个键对应的值,若失效则返回null
  • set(key,value,expi) — 为某个键设置值及失效时间
  • remove(key) — 移除某个键对应的值

Example

import { useStorage} from 'chooks'
export default {
    setup(){
        const { get, set, remove } = useStorage({
            keyBase: "test",
            expires: 10000
        })

        set("a", 1, 10)
        get("a")
        remove("a")

        return {}
    }
}