I want to pass data through function of VUE to a new page on click of a button. I tried doing this thing using the router method but i was not able to send the array it was just allowing me to send a string with it.
this.$router.push({
name: "SalesInvoice",
params: { SalesInvoice: this.stockmaster }
});
this thing is not working beacuse the stockmaster is an array.
this.$router.push({
name: "SalesInvoice",
params: { SalesInvoice: "abc" }
});
the same thing i did with string and it worked. so is there any way of sending array to next page using vue method.
With Vue Router, you can use its router. push() function to programmatically navigate between routes on your site. You can either call push() with a string path, or with an object containing either the path or name of the route.
You can use $router. push({ name: "yourroutename"}) or just router. push("yourroutename") now to redirect.
Just adding my comment as an answer so others can get it easily in the future.
When you are trying to pass an array, object or array of objects to the router, you should first stringify
your data with JSON.stringify
and the pass it to the router. And then you can access it and parse it back to JSON
with JSON.parse
. For the particular case above, something like following should be done
this.$router.push({
name: "SalesInvoice",
params: { SalesInvoice: JSON.stringify(this.stockmaster) }
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With