Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
}
Comment

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,
  },
};
Comment

vue axios post return json data

// response is full Response object, with URL, headers, method and etc.
axios.post("http://localhost:8080/api/some/awesome/endpoint", postData)
	.then(response => console.log(response.data));
// no need for .json method, becouse response.data already is JS object
Comment

Access data out of Axios .then vue.js


created() {
    var self = this;
    axios.get('http://127.0.0.1/api/bills')
        .then(function (response) {
                self.contas = response.data;
                });
}

Comment

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));
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: clear ckeditor textarea jquery 
Javascript :: script defer attribute 
Javascript :: collision javascript 
Javascript :: Delete a user in ExpressJS 
Javascript :: set proxy for npm 
Javascript :: javascript filter array return index 
Javascript :: slice in javascript 
Javascript :: react write into json file 
Javascript :: javascript detect paste contents 
Javascript :: node check text include in file 
Javascript :: javascript reduce return array 
Javascript :: create index mongodb 
Javascript :: compare two dates in javascript 
Javascript :: Google App Script getSheetByName 
Javascript :: random word react npm package 
Javascript :: random number generator 
Javascript :: how to global a variable in javascript 
Javascript :: GoogleMap: center or defaultCenter property must be defined 
Javascript :: javascript Short and Long date format 
Javascript :: yarn install python2 not found 
Javascript :: opposite of includes javascript 
Javascript :: react native choose simulator 
Javascript :: create express app 
Javascript :: repeating countdown timer javascript 
Javascript :: unexpected token w in json at position 0 
Javascript :: perfect scrollbar jquery 
Javascript :: svg clientx 
Javascript :: How to loop through an object in JavaScript with the Object.keys() method 
Javascript :: loop over documents in mongoose 
Javascript :: react setstate concat string 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =