cklmercer / vue-stash

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

Access $store in `beforeRouteEnter` (vue-router) #16

Closed zatziky closed 7 years ago

zatziky commented 7 years ago

According to vue-router docs the this is not available in beforeRouteEnter hook:

beforeRouteEnter (to, from, next) {
    // called before the route that renders this component is confirmed.
    // does NOT have access to `this` component instance,
    // because it has not been created yet when this guard is called!
  },

To access the store directly vue-stash sets Vue.prototype.$store. Is there a way how to access the store without any Vue instance?

zatziky commented 7 years ago

Writing this I have just realized that I can create a Vue instance and access $store. :)

(new Vue()).$store