4

I'm developing a site that receives some URL parameters. When the parameters are sent by HTTP GET I can receive then, example:

Calling the site:

http://localhost:8080/#/Home?status=2

Showing the received the parameters, inside any js function:

console.log(this.$route.query.status)

The GET is working fine.

But when I sent the same parameter using HTTP POST, I don't know how to receive it. I used the postman program to send this.

I tried showing it using the $route.params:

console.log(this.$route.params.status)

But no success.

How to receive HTTP POST parameters on vue.js?

I found this guide at the vuejs site:

data-fetching

But it still needs a getPost function.

EDIT

My router/index.js is this:

import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/components/Home'


Vue.use(Router)

export default new Router({
  routes: [
    {
        path: '/',
        name: 'Root',
        component: Home
    },
    {
        path: '/Home',
        name: 'Home',
        component: Home
    }
  ]
})
Derzu
  • 7,011
  • 3
  • 57
  • 60
  • 1
    "But when I sent the same parameter using HTTP POST", how did you do this? using axios or what? – You Nguyen Sep 16 '19 at 01:47
  • 1
    @NguyenYou, I sent using an external program, the postman. – Derzu Sep 16 '19 at 01:48
  • You can't read POST parameters directly on the front-end. They are received on the server end. You will need a mechanism for the server to pass it along to the front end. – Kei Sep 16 '19 at 02:04
  • @Kei, do you have any suggestions for a mechanism that can do that? – Derzu Sep 16 '19 at 02:08
  • 1
    @NguyenYou, I just add my router/index.js to the question. – Derzu Sep 16 '19 at 02:16
  • 1
    @Derzu well, how did you send the GET request? using what? Can you send the GET request using Postman? – You Nguyen Sep 16 '19 at 02:29
  • 2
    @NguyenYou, I sent the GET using directly the browser. – Derzu Sep 16 '19 at 02:32
  • @NguyenYou, I tried to send the GET parameter at the postman also, it appears to work but the page is not completed download because the postman preview does not execute the javascript. – Derzu Sep 16 '19 at 02:36
  • @YomS. I'm not doing a request and waiting for a response. I wanna that the client-side render different information based on the parameters that it receives. I can do that reading the GET parameters, but I don't know how to do using POST parameters. – Derzu Sep 16 '19 at 02:49
  • @Derzu So, the real question is how to handle the POST request body without using a backend server like nodejs, rubyonrails, etc? – You Nguyen Sep 16 '19 at 02:56
  • @NguyenYou yes. – Derzu Sep 16 '19 at 03:03
  • @Derzu as far as I know, you can't do it. Btw, there is nothing to do with vuejs, the question can be simplified to, how to handle the Post request body using javascript? Here is the question & answer: [how-to-read-the-post-request-parameters-using-javascript](https://stackoverflow.com/questions/1409013/how-to-read-the-post-request-parameters-using-javascript) – You Nguyen Sep 16 '19 at 03:12
  • @NguyenYou Yes, thanks. – Derzu Sep 16 '19 at 03:17

0 Answers0