Skip to content

Instantly share code, notes, and snippets.

@chrisvasey
Last active March 10, 2020 19:34
Show Gist options
  • Save chrisvasey/3152e7e77d76eb71be099ef1afdba6ea to your computer and use it in GitHub Desktop.
Save chrisvasey/3152e7e77d76eb71be099ef1afdba6ea to your computer and use it in GitHub Desktop.
Using Ajax responses in vue
<script>
export default {
date(){
return {
data: {
value: "", //value I want to set
}
}
},
methods(){
save(){
var self = this;
axios.post('/test', this.data, {
}).then(function (response) {
//"this" won't work here because it refers to the promise. I am using the verable of "self" I set up above instead
self.value = response.first_name; //something from the response
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment