78
rated 0 times
[
85]
[
7]
/ answers: 1 / hits: 64311
/ 7 Years ago, thu, may 4, 2017, 12:00:00
I am trying to post my form using axios, but I am not able to get the data to my backend using expressjs
This is what I am doing:
<template>
<form class= method=post @submit.prevent=postNow>
<input type=text name= value= v-model=name>
<button type=submit name=button>Submit</button>
</form>
</template>
export default {
name: 'formPost',
data() {
return {
name: '',
show: false,
};
},
methods: {
postNow() {
axios.post('http://localhost:3030/api/new/post', {
headers: {
'Content-type': 'application/x-www-form-urlencoded',
},
body: this.name,
});
},
components: {
Headers,
Footers,
},
};
backend file:
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
router.post('/new/post', (req, res) => {
res.json(console.log(this is working + ' ' + req.body.name));
});
The error I am receiving is:
this is working undefined
More From » node.js