Options
All
  • Public
  • Public/Protected
  • All
Menu

Module vx-tools/localSave

本地缓存包装函数

Index

Functions

buildGetItem

  • buildGetItem(storage: typeof localStorage | typeof sessionStorage): <T>(key: string) => T | null
  • Parameters

    • storage: typeof localStorage | typeof sessionStorage

    Returns <T>(key: string) => T | null

      • <T>(key: string): T | null
      • Type parameters

        • T = any

        Parameters

        • key: string

        Returns T | null

buildSetItem

  • buildSetItem(storage: typeof localStorage | typeof sessionStorage): <T>(key: string, data: T) => void
  • Parameters

    • storage: typeof localStorage | typeof sessionStorage

    Returns <T>(key: string, data: T) => void

      • <T>(key: string, data: T): void
      • Type parameters

        • T = any

        Parameters

        • key: string
        • data: T

        Returns void

registSaveFn

  • registSaveFn(): void
  • 本地缓存包装函数

    summary

    为本地缓存对象 localStorage,sessionStorage 添加 setItem getItem 包装函数 包装函数将原字符参数或返回值通过JSON转换为对象

    remind

    因为使用JSON对数据做转换, 数据格式必须服务json格式, 所以报错纯字符时将报错, 此时可以使用原生方法

    example
    import { registSaveFn } from '@micro/utils'
    registSaveFn() //全局调用一次
     
    const saveKey = 'USER'
    localStorage.$setItem(saveKey, { name: 'copy', sex: 'man' })
    const user = localStorage.$getItem(saveKey)
    console.log(user.name)
    

    Returns void

Generated using TypeDoc