Skip to content

Instantly share code, notes, and snippets.

@jagroop
Created September 26, 2018 11:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jagroop/cc435311a63f6244caa8701d92a94142 to your computer and use it in GitHub Desktop.
Save jagroop/cc435311a63f6244caa8701d92a94142 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
</head>
<body>
<div id="app">
<ul v-for="(post, index) in posts">
<li>{{ post.title }}</li>
</ul>
</div>
<script>
var app = new Vue({
el: '#app',
data() {
return {
posts: [],
}
},
mounted() {
this.getPosts();
},
methods: {
getPosts() {
var vm = this;
axios.get('https://jsonplaceholder.typicode.com/posts').then(function(response){
vm.posts = response.data;
}).catch(function(err){
console.log('Something went wrong.');
});
}
}
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment