Created
May 8, 2019 19:27
-
-
Save madeindjs/f56f6d5a7cf3386611ce02be532ae962 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html lang="fr"> | |
<head> | |
<meta charset="utf-8"> | |
<title>TODO front-end</title> | |
</head> | |
<body> | |
<div id="app"> | |
<table> | |
<tr> | |
<th>id</th> | |
<th>title</th> | |
<th>user</th> | |
<th>completed</th> | |
</tr> | |
<tr v-for="todo in todos"> | |
<td>{{ todo.id }}</td> | |
<td>{{ todo.title }}</td> | |
<td> | |
<button type="button" @click="showUser(todo.userId)"> | |
{{ todo.userId }} | |
</button> | |
</td> | |
<td>{{ todo.completed }}</td> | |
</tr> | |
</table> | |
<button v-on:click="loadTodos">Load todos</button> | |
</div> | |
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script> | |
<script type="text/javascript"> | |
var app = new Vue({ | |
el: '#app', | |
data: { | |
todos: [], | |
}, | |
methods: { | |
loadTodos: function() { | |
fetch('https://jsonplaceholder.typicode.com/todos/') | |
.then(response => response.json()) | |
.then(json => { | |
this.todos = json; | |
}) | |
}, | |
showUser: function(userId) { | |
fetch('https://jsonplaceholder.typicode.com/users/' + userId) | |
.then(response => response.json()) | |
.then(json => alert(json.email) ) | |
} | |
} | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment