cklmercer / vue-stash

Easily share reactive data between your Vue components.
MIT License
403 stars 29 forks source link

Access vue-stash from non component #10

Closed OmgImAlexis closed 7 years ago

OmgImAlexis commented 7 years ago

Currently I use another file to setup an api and then import the file into my components, is there a way to access the current store inside of those?

import axios from 'axios';

var api = axios.create({
    baseURL: config.auth.url, // This should be from the vue-stash store
    timeout: 10000,
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'X-Api-Key': config.auth.key // This should be from the vue-stash store
    }
});

export default api;
cklmercer commented 7 years ago

vue-stash just helps you access your root VM's data option. That said, if you save your root VM to a variable then you should be able to access your store from there.

const app = new Vue({
  data: {
    store: {
        message: 'hello world'
    }
  }
})

console.log(app.data.store.message)

Then you can export