vue-save-storage

1.0.1 • Public • Published

vue-save-storage


Install

npm install --save vue-save-storage

Usage

import Vue from 'vue'
import storage from 'vue-save-storage'
// 默认引入为localstorage
Vue.prototype.$storage = storage
import Vue from 'vue'
import {local, session} from 'vue-save-storage'
// localstorage, session
Vue.prototype.$local = local
Vue.prototype.$session = session

Nuxt.js

可以在Nuxt.js中使用vue-save-storage

vue-save-storage必须作为NuxtJS插件包含在内:

// nuxt.config.js
plugins: [{ src: '~/plugins/storage.js', ssr: false }]

API

localStorage and sessionStorage

  • setItem(key, value<any>): value可以为对象、数组或者基本类型
  • getItem(key<string>): 获取localStorage或者sessionStorage中设置的值。
  • remove(key<string>): 移除localStorage或者sessionStorage中某一个值
  • clear(): 移除localStorage或者sessionStorage中所有的值

Package Sidebar

Install

npm i vue-save-storage

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

7.24 kB

Total Files

5

Last publish

Collaborators

  • cnbrian