Last active
March 10, 2020 19:34
-
-
Save chrisvasey/3152e7e77d76eb71be099ef1afdba6ea to your computer and use it in GitHub Desktop.
Using Ajax responses in vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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