Deprecated. Use Vuex and Vuex-Persist instead.
Provides a persistent "database" object for Vue applications.
-
Run
npm install --save @scriptpilot/vue-mixin-databaseto install the package -
Add the mixin to your Vue application:
import Vue from 'vue' import databaseMixin from '@scriptpilot/vue-mixin-database' ... Vue.mixin(databaseMixin) ... new Vue(...)
As a global mixin, you can you use the $db(...) function in any template or script.
- To read:
$db('path') - To write:
$db('path', 'value') - To delete:
$db('path', null)
path can be simple or nested.
Nested path:
$db('a[0].b.c', 123)
console.log($db(a[0].b)) // => { c: 123 }In the template:
<template>
<div>
<p>Value: {{$db('key')}}</p>
<p><button @click="$db('key', 'new value')">Update the Value</button></p>
<p><button @click="$db('key', null)">Delete the Value</button></p>
</div>
</template>In the script:
<script>
export default {
created() {
this.$db('key', 'old value')
}
}
</script>