Created
October 23, 2017 15:14
-
-
Save bussiere/458b12ba854516c2be880bc9dff9fb87 to your computer and use it in GitHub Desktop.
vue and axios
This file contains 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
<html> | |
<script src="https://unpkg.com/vue"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.17.0/axios.js"></script> | |
<body> | |
<div id="app-3"> | |
<span v-if="seen">{{ textFromApi }}</span> | |
</div> | |
<br/> | |
<script type="text/javascript"> | |
var app3 = new Vue({ | |
el: '#app-3', | |
data: { | |
seen: true, | |
textFromApi: "hello" | |
}, | |
methods: { | |
getData() { | |
return axios.get('https://jsonplaceholder.typicode.com/posts/1').then(response => { | |
this.textFromApi = response.data | |
}) | |
}, | |
}, | |
created: function () { | |
this.textFromApi = this.getData(); | |
} | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment