-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexercise_1_complete.html
55 lines (54 loc) · 1.23 KB
/
exercise_1_complete.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
[v-cloak] {
display: none;
}
</style>
<script src="https://unpkg.com/vue"></script>
<!-- minified version for production ->
<!--script src="https://unpkg.com/[email protected]/dist/vue.min.js"></script-->
<script>
function randomName(callback){
fetch('https://randomuser.me/api/').then( function(response){
return response.json()
}).then( function(json) {
callback(json.results[0].name.first + ' ' + json.results[0].name.last)
})
}
</script>
</head>
<body>
<div id="app" v-cloak>
<p>name: {{ name }}</p>
<p>
<input v-model="name"/>
</p>
<p>
<button v-on:click="reverse()">reverse</button>
<button v-on:click="fetchName()">fetch a name</button>
</p>
</div>
<script>
new Vue({
el: '#app',
data: {
name: 'SDS'
},
methods: {
reverse() {
this.name = this.name.split("").reverse().join("")
},
fetchName() {
let that = this
randomName(function(name){
that.name = name
})
}
}
})
</script>
</body>
</html>