1// response is full Response object, with URL, headers, method and etc.
2axios.post("http://localhost:8080/api/some/awesome/endpoint", postData)
3 .then(response => console.log(response.data));
4// no need for .json method, becouse response.data already is JS object
1<template>
2 <form class="" method="post" @submit.prevent="postNow">
3 <input type="text" name="" value="" v-model="name">
4 <button type="submit" name="button">Submit</button>
5 </form>
6</template>
7
8export default {
9 name: 'formPost',
10 data() {
11 return {
12 name: '',
13 show: false,
14 };
15 },
16 methods: {
17 postNow() {
18 axios.post('http://localhost:3030/api/new/post', {
19 headers: {
20 'Content-type': 'application/x-www-form-urlencoded',
21 },
22 body: this.name,
23 });
24 },
25 components: {
26 Headers,
27 Footers,
28 },
29};
1app.use(bodyParser.json());
2app.use(bodyParser.urlencoded({ extended: true }));
3router.post('/new/post', (req, res) => {
4 res.json(console.log("this is working" + ' ' + req.body.name));
5});