is there some simple way how to read POST request parameters in nuxtjs asyncData function? Thanks a lot.
Here's an example:
Form.vue:
<template>
<form method="post" action="/clickout" target="_blank">
<input type="hidden" name="id" v-model="item.id" />
<input type="submit" value="submit" />
</form>
</template>
submitting previous form routes to following nuxt page:
Clickout.vue
async asyncData(context) {
// some way how to get the value of POST param "id"
return { id }
}
Finally I found following way how to solve that. I'm not sure if it's the best way, anyway it works :)
I needed to add server middleware server-middleware/postRequestHandler.js
nuxt.config.js
Clickout.vue
I recommend to not use the default behavior of
form
element, try to define a submit handler as follows :and submit method as follows :
in the target component do:
When asyncData is called on server side, you have access to the req and res objects of the user request.
ref. https://nuxtjs.org/guide/async-data/#use-code-req-code-code-res-code-objects