Answers for "Access data out of Axios .then vue.js"

1

Access data out of Axios .then vue.js

data() {
	return {
    	variable: null
    }
}

mounted() {
    axios.get(url)
     .then(function (response) {
        this.variable = response.data
     }.bind(this)) //You need to put .bind(this) to keep the scoped variable
}
Posted by: Guest on October-03-2021
1

axios post data vue js

<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,
  },
};
Posted by: Guest on March-30-2020
0

axios post data vue js

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));
});
Posted by: Guest on March-30-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language