B
B
beduin012019-07-04 11:14:45
Vue.js
beduin01, 2019-07-04 11:14:45

How to reach a variable declared in a Vue instance?

I found a wrapper for caching https://www.npmjs.com/package/vue-idb
I can't figure out how to use it correctly using the example from the documentation:

import Vue from 'vue'
import VueIdb from 'vue-idb'
 
Vue.use(VueIdb)
 
const idb = new VueIdb({
  version: 1,
  database: 'test',
  schemas: [
    { tests: 'id, title, created_at, updated_at' },
  		{ posts: 'id, owner' }
  ]
})
 
new Vue({
  el: '#app',
  idb: idb,
  render: h => h(App)
})

How can I access `idb` inside my component?
axios.get(base_url + '/api/industry')
        .then((response) => {
          idb.test= response.data; // так не получается
        })
        .catch((error) => {
          console.log(error);
        });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Drozdov, 2019-07-04
@bagzon

this.$db or vm.$db
Here is how it is injected into the prototype of the view in the source code.
https://github.com/ddgll/vue-idb/blob/dbe43f7e77bd...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question