How To Read Post Request Parameters In Nuxtjs?
is there some simple way how to read POST request parameters in nuxtjs asyncData function? Here's an example: Form.vue:
Solution 2:
I recommend to not use the default behavior of form
element, try to define a submit handler as follows :
<template><form @submit.prevent="submit"><inputtype="hidden"name="id"v-model="item.id" /><inputtype="submit"value="submit" /></form></template>
and submit method as follows :
methods:{
submit(){
this.$router.push({ name: 'clickout', params: { id: this.item.id } })
}
}
in the target component do:
asyncData(context) {
returnthis.$route.params.id;
}
Solution 3:
When asyncData is called on server side, you have access to the req and res objects of the user request.
exportdefault {
async asyncData({ req, res }){
// Please check if you are on the server side before// using req and resif (process.server) {
return { host: req.headers.host }
}
return {}
}
}
ref. https://nuxtjs.org/guide/async-data/#use-code-req-code-code-res-code-objects
Solution 4:
Maybe it is a little bit late but I think this might help.
In your .vue file get the nuxt router route object:
this.$route
It stores some useful information like the path, hash, params and the query.
Take a look at this for more details on this.
Post a Comment for "How To Read Post Request Parameters In Nuxtjs?"