0.0.8 • Published 2 years ago

js-van v0.0.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

js-van

Version

前端数据持久化方案,支持cookie与storage。

安装与使用

通过npm安装

npm install js-van

使用

import { set, get, remove, VanType } from 'js-van'

// 存储数据
set('key', 'value', { type: VanType.localStorage, expires: '' })
// 获取数据
get('key', { type: VanType.cookie })
// 删除数据
remove('key', { type: VanType.sessionStorage })

方法说明

set

存储数据到cookie或storage。当不设置type时,默认存储到localStorage。支持expires设置,当expires设置为数字时,所存储的数据将存在有效期;当expires不是数字时,该属性无效。

参数

$key: string

$value: any

$options?: VanOptions

get

获取存储的数据,如果数据不存在或超出有效期,返回null。

参数

$key: string

$options?: VanOptions

remove

删除数据。

参数

$key: string

$options?: VanOptions

对象说明

VanOptions

选项配置

属性

type?: VanType

expires?: number | string

domain?: string

枚举说明

VanType

localStorage

sessionStorage

cookie

0.0.8

2 years ago

0.0.5

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago