@ylz/plugins
Version:
ylz plugins
29 lines (27 loc) • 672 B
JavaScript
import localforage from 'localforage'
function LocalForageFactory() {
this.instance = null
this.createInstance = (options) => {
if (this.instance === null) {
this.instance = localforage.createInstance(options)
}
return this.instance
}
}
const install = (Vue, options) => {
const localForageFactory = new LocalForageFactory()
Object.defineProperty(Vue.prototype, '$localForage', {
get() {
return localForageFactory.createInstance(options)
}
})
Object.defineProperty(Vue, 'localForage', {
get() {
return localForageFactory.createInstance(options)
}
})
}
export default {
install,
localForage: localforage
}