@phoenix-cg/storage
v1.0.4
Published
Phoenix-cg storage package
Downloads
46
Readme
Storage
localStorage
is a property that allows JavaScript sites and apps to save key-value pairs in a web browser with no expiration date.
sessionStorage
allows you to store data in the browser depending on the system memory and the data stored in the browser until the browser is closed.
Storage is a class to add or remove item from local or session storage.
Installation
npm i @phoenix-cg/storage
Methods
| Method | Description |
|-----------------------|-------------------------------------------------|
| setItem(key, value) | Add key and value to localStorage
|
| getItem(key) | This is how you get items from localStorage
|
| removeItem(key) | Remove an item from localStorage
|
Usage
import { storageLocal, storageSession } from '@phoenix-cg/storage'
...
methods: {
clientMounted () {
const bannerShown = this.storageLocal.getItem('banner-shown')
if (showBanner) {
this.showBanner()
}
this.storageLocal.setItem('banner-shown', 1)
},
...
hideBanner () {
this.popupResetTimeoutId = setTimeout(() => {
this.storageLocal.getItem('banner-shown')
}, 100)
},
resetBanenr () {
this.storageLocal.removeItem('banner-shown')
}
}