File tree Expand file tree Collapse file tree 3 files changed +84
-0
lines changed Expand file tree Collapse file tree 3 files changed +84
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments