import Vue from 'vue' ; class MiStorage { private instance : Storage = localStorage ; param type constructor ( type ? ) { if ( type && type === 'session' ) this . instance = sessionStorage ; } param keys public get ( keys ) { let data = { } ; if ( Array . isArray ( keys ) ) { for ( let i = 0 , len = keys . length ; i < len ; i ++ ) { const key = keys [ i ] , item = `${ process . env . VUE_APP_PREFIX }${ key }` ; data [ key ] = JSON . parse ( this . instance . getItem ( item ) as string ) ; } } else { data = null ; const key = `${ process . env . VUE_APP_PREFIX }${ keys }` ; if ( keys ) data = JSON . parse ( this . instance . getItem ( key ) as string ) ; } return data ; } param key param value public set ( key , value ) { const item = `${ process . env . VUE_APP_PREFIX }${ key }` ; this . instance . setItem ( item , JSON . stringify ( value ) ) ; } param keys public del ( keys ) { if ( Array . isArray ( keys ) ) { for ( let i = 0 , len = keys . length ; i < len ; i ++ ) { const key = keys [ i ] , item = `${ process . env . VUE_APP_PREFIX }${ key }` ; this . instance . removeItem ( item ) ; } } else { const item = `${ process . env . VUE_APP_PREFIX }${ keys }` ; this . instance . removeItem ( item ) ; } } } declare module 'vue/types/vue' { interface Vue { storage : MiStorage ; } } const instance = new MiStorage ( ) ; Vue . prototype . storage = instance ; export const storage = instance ;