Vue3 plugin for work with local storage, session storage and websql from Vue context, inspired by tarojs and vue-ls.
npm install vue3-storage``shinstall with yarn
yarn add vue3-storage
$3
The main version Supports Vue 3.x only
Usage
$3
Register
`js
import Vue3Storage from "vue3-storage";const app = createApp(App);
app.use(router)
.use(Vue3Storage, { namespace: "pro_", storage: StorageType.Local })
.mount("#app");
`
if you not set plugin options, default { namespace: "pro_", storage: StorageType.Local }
$3
use Global ComponentCustomProperties `this.$storage``vue

`You can still use it like this:
``vue

``You can still use it like this:
`vue
`Use promise
`js
`Storage API
`ts
export interface StorageInterface {
/**
* Asynchronous storage
* @param option
*/
getStorage(option: GetStorageOption): Promise>;
/**
* Synchronous storage
*
* @param key
*
*/
getStorageSync(key: string): T | undefined;
/**
* Synchronously obtain the storage content of the corresponding key
*
* @param key
* @param data
* @param expire
*/
setStorageSync(key: string, data: any, expire?: number): void;
/**
* Asynchronously obtain the storage content of the corresponding key
*
* @param option
*/
setStorage(option: SetStorageOption): Promise;
/**
* Determine whether the data has expired
* @param key
*/
isExpire(key: string): boolean;
/**
* Correspondingly obtained key name index
* @param index
*/
key(index: number): string | null;
/**
* Determine whether the key name exists
*
* @param key
*/
hasKey(key: string): boolean;
/**
* Asynchronously remove the specified key from the local cache
*
* @param option
*/
removeStorage(option: RemoveStorageOption): Promise;
/**
* Synchronously remove the specified key from the local cache
*
* @param name
*/
removeStorageSync(name: string): void;
/**
* Get current storage information asynchronously
*
* @param option
*/
getStorageInfo(option?: GetStorageInfoSuccessCallbackOption): Promise;
/* Get current storage information synchronously /
getStorageInfoSync(): GetStorageInfoOption;
/**
* Clean up local data cache asynchronously
* @param option
*/
clearStorage(option?: ClearStorageOption): Promise;
/**
* Synchronously clean the local data cache
*/
clearStorageSync(): void;
/**
* Set storage namespace
* @param namespace
*/
config(namespace?: string): void;
}
``MIT