blue4euro4
blue4euro4

Reputation: 43

Passing an array to another page through vue

I am currently trying to pass an array thats accessible on one page to the next. The next page is accessed on a forms submission using this.$router.push('path')

Is there any way for me to pass the array over as well when submitting the form so that I can access it on the new page?

Upvotes: 2

Views: 793

Answers (2)

Ryrayer
Ryrayer

Reputation: 1

If you don't wanna use vuex or other store managers then the simplest way could be doing

this.$router.push('path').then(() => { this.$route.params.yourArray = ['value'] })

and then in the destination component use that same

this.$route.params.yourArray

Upvotes: 0

kissu
kissu

Reputation: 46696

You can't do that with Vue router directly as explained in this answer, you can only pass String type.

If you want to access it on another page, you can either:

  • store it in cookies or localStorage (not recommended)
  • fetch it from the submission: the backend probably gives you a response
  • use Vuex or even some state that can overlap between the current and next page

Upvotes: 2

Related Questions