zan-wx-storage
TypeScript icon, indicating that this package has built-in type declarations

1.0.12 • Public • Published

小程序缓存

仅支持微信小程序项目

安装

npm i zan-wx-storage

使用

import { setStorage } from 'zan-wx-storage'

API

设置缓存 setStorage

/**
 * @param   {string}  key     [key]
 * @param   {any}     value   [value]
 * @param   {number}  expire  [expire 过期时间,如: 24 * 60 * 60 = 1天]
 * @return  {void}            [return]
 */
declare const setStorage: (key: string, value: any, expire?: number) => void;

示例: 过期时间格式,参考上类型定义中说明

import { setStorage } from 'zan-wx-storage'

setStorage('name', 1) // NAME => 1

获取缓存 getStorage

示例: 如缓存设置了有效期,失效则返回null

import { getStorage } from 'zan-wx-storage'

getStorage('name') // 1

移除缓存 removeStorage

示例:

import { removeStorage } from 'zan-wx-storage'

removeStorage('name') // null

设置缓存命名空间 setStorageNameSpace

示例: 一般在项目入口文件设置

import { setStorageNameSpace } from 'zan-wx-storage'

setStorageNameSpace('zan') // ZAN-NAME => 1

Package Sidebar

Install

npm i zan-wx-storage

Weekly Downloads

3

Version

1.0.12

License

MIT

Unpacked Size

4.41 kB

Total Files

6

Last publish

Collaborators

  • wvlvik