1data() {
2 return {
3 variable: null
4 }
5}
6
7mounted() {
8 axios.get(url)
9 .then(function (response) {
10 this.variable = response.data
11 }.bind(this)) //You need to put .bind(this) to keep the scoped variable
12}
13
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});