Skip to content

Commit af55c0f

Browse files
willwill
authored andcommitted
add vue-5
1 parent a2b0834 commit af55c0f

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.DS_Store
2+
node_modules/
3+
dist/
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Editor directories and files
9+
.idea
10+
.vscode
11+
*.suo
12+
*.ntvs*
13+
*.njsproj
14+
*.sln

vue-5-dynamic-data/index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>Document</title>
9+
</head>
10+
11+
<body>
12+
<h1>My Friends</h1>
13+
<div id="app"></div>
14+
15+
<script src="https://unpkg.com/vue"></script>
16+
<script src="./main.js"></script>
17+
</body>
18+
19+
</html>

vue-5-dynamic-data/main.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const app = new Vue({
2+
el: "#app",
3+
data: {
4+
editFriend: null,
5+
friends: [],
6+
},
7+
methods: {
8+
deleteFriend(id, i) {
9+
fetch("http://rest.learncode.academy/api/vue-5/friends/" + id, {
10+
method: "DELETE"
11+
})
12+
.then(() => {
13+
this.friends.splice(i, 1);
14+
})
15+
},
16+
updateFriend(friend) {
17+
fetch("http://rest.learncode.academy/api/vue-5/friends/" + friend.id, {
18+
body: JSON.stringify(friend),
19+
method: "PUT",
20+
headers: {
21+
"Content-Type": "application/json",
22+
},
23+
})
24+
.then(() => {
25+
this.editFriend = null;
26+
})
27+
}
28+
},
29+
mounted() {
30+
fetch("http://rest.learncode.academy/api/vue-5/friends")
31+
.then(response => response.json())
32+
.then((data) => {
33+
this.friends = data;
34+
})
35+
},
36+
template: `
37+
<div>
38+
<li v-for="friend, i in friends">
39+
<div v-if="editFriend === friend.id">
40+
<input v-on:keyup.13="updateFriend(friend)" v-model="friend.name" />
41+
<button v-on:click="updateFriend(friend)">save</button>
42+
</div>
43+
<div v-else>
44+
<button v-on:click="editFriend = friend.id">edit</button>
45+
<button v-on:click="deleteFriend(friend.id, i)">x</button>
46+
{{friend.name}}
47+
</div>
48+
</li>
49+
</div>
50+
`,
51+
});

0 commit comments

Comments
 (0)