4

I'm new to vuejs, I'm trying to do some data downloading from inside Vue View, using function inside methods, I wonder if I leave that view(change route), is the downloading process still running? (in this case I'm downloading from firestore, some huge databases)

Any advice on how it should be done? So that the database download keep running regardless of route change?

Any help is much appreciated

Edit: To clarify, my case are like this :

  1. User open some page
  2. The page download some data in background(will take some time)
  3. User move to another page

What I'm asking are how did I make the data download process continue running, even though user move to another route?

2 Answers 2

3

If you are developing an SPA with Vue Router, the keep-alive element might help you in this issue.

Basically, according to the Vue JS Lifecycle Diagram, once a component is destroyed, all directives of the Vue instance have been unbound, all event listeners have been removed, and all child Vue instances have also been destroyed.

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

6 Comments

Thanks for responding, I'm sorry I just edited my questions with my case detail, so will keep-alive work in my case? Are there nothing in Vue that work in background regardless the route?
Are you using Vue Router router-view?
Yes,, I'm using Vue router
Then yes, keep-alive will help you in your case. That will cache the state, reading progress, etc. of a router-view so you don't have to download that page every time.
Again, thanks for the suggestions, but if I don't want to use keep-alive, can I write the download function in vuex action, and call it from component? Will it became background process? (when I move to other route, the vuex action will still running
|
1

In my case, I finally put the function inside vuex action, and call it using this.$store.dispatch(function name). It work flawlessly. even though I keep changing route/view, the bg process(action) keep running.

notes: I don't need the downloaded data to be binded/reactive, I just need to download the data in background and save it to localforage

Comments

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.