1

I'm doing async work in my router's navigation guard:

router.beforeEach((to, from, next) => {
  somethingAsync().done(next)
})

Does the router expose anything to tell me that it's currently "loading"? Or do I need to keep track of it myself? Right now the content will pop up in<router-view></router-view> once the async work is completed. My current solution is to keep track of active work in my Vuex store and show a loading element next to the router view.

1 Answer 1

3

What I do to achieve what I think you are trying to is this:

  • Use Axios or something else that has interceptors https://github.com/mzabriskie/axios
  • Have a component that have a counter of pending requests. When that counter is higher than 0, show the loading element.
  • After that all you have to do is configure the interceptors so that when a request is made the counter goes up, and when a response is received the counter goes down.

I could show you some code if you need.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah that it what I do in my Vuex store today :) I was curious if something was built in so I'm not reinventing the wheel

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.