utils-storage-ts
v2.0.2
Published
storage
Downloads
2
Maintainers
Readme
install
npm
npm install utils-storage-ts
yarn
yarn add utils-storage-ts
usage
Using examples in Vue3
main.js
import config from './config'
import { initLocalStorage, initSessionStorage } from 'utils-storage-ts'
app.config.globalProperties.$localStorage = initLocalStorage(config.namespace)
app.config.globalProperties.$sessionStorage = initSessionStorage(config.namespace)
test.vue ( without setup )
mounted () {
/**
*@param1: key,
*@param2: value,
*@param3: time(The unit is *seconds),
*@return: void
*/
this.$localStorage.setItem('name', 'jitong', 3000)
this.$sessionStorage.setItem('name', 'jitong', 3000)
/**
*@param: key,
*@return: value || false
*/
this.$localStorage.getItem('name')
this.$sessionStorage.getItem('name')
/**
*@param: key,
*@return: void
*/
this.$localStorage.removeItem('name')
this.$sessionStorage.removeItem('name')
/**
*@param: void,
*@return: void
*/
this.$localStorage.clear()
this.$sessionStorage.clear()
}
test.vue ( with setup )
import { initLocalStorage, initSessionStorage } from 'utils-storage-ts'
export default {
setup () {
const localStorage = initLocalStorage(namespace)
const sessionStorage = initSessionStorage(namespace)
}
}