Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing functions from outside modules #21

Open
ghost opened this issue Oct 7, 2018 · 2 comments
Open

Accessing functions from outside modules #21

ghost opened this issue Oct 7, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Oct 7, 2018

Is there a way to access the store functions ive set up in router guard methods, they all work fine inside modules themselves but i cant seem to get them working outside of those.

@two48
Copy link

two48 commented Dec 9, 2018

Here is an example of one way you could use this inside a router guard method:

import Vue from 'vue';
import Router from 'vue-router';

import store from '@/stores/store.ts';
import { dispatchLoadCartItems } from '@/stores/cart/index.ts';

Vue.use(Router);

export default new Router({
  routes: [
    {
      path: '/',
      redirect: '/cart',
      name: 'cart',
      beforeEnter: (to, from, next) => {
        dispatchLoadCartItems(store)
          .then(() => next())
          .catch(() => next('/cart-error'));
      },
    },
  ],
});

@ghost
Copy link
Author

ghost commented Dec 12, 2018

@levxo Ive got something simlar but on first load, the store is undefined. Ive got a bandaid solution by calling a method that checks if its undefined and recalls itself until the store is defined. Seems really weird

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant