File tree 4 files changed +19
-16
lines changed
4 files changed +19
-16
lines changed Original file line number Diff line number Diff line change 10
10
export default {
11
11
name: ' BookForm' ,
12
12
props: [' books' ],
13
- data () {
13
+ data () {
14
14
return {
15
15
bookTitle: ' ' ,
16
16
bookAuthor: ' ' ,
17
- }
17
+ };
18
18
},
19
19
methods: {
20
- bookSubmit (bookTitle , bookAuthor ){
21
- this .$emit (' addBook' , bookTitle, bookAuthor)
22
- }
20
+ bookSubmit (bookTitle , bookAuthor ) {
21
+ this .$emit (' addBook' , bookTitle, bookAuthor);
23
22
},
23
+ },
24
24
};
25
25
</script >
26
26
Original file line number Diff line number Diff line change 4
4
<ul >
5
5
<book-item
6
6
v-for =' book in books'
7
- :key =' book'
7
+ :key =' book.id '
8
8
:book =' book'
9
9
></book-item >
10
10
</ul >
11
11
<br >
12
12
<book-form @addBook =' appendBook' ></book-form >
13
13
<br ><hr >
14
- <book-suggestions ></book-suggestions >
14
+ <book-suggestions @appendBook = ' appendBook ' ></book-suggestions >
15
15
</div >
16
16
</template >
17
17
@@ -40,9 +40,9 @@ export default {
40
40
},
41
41
methods: {
42
42
appendBook (bookTitle , bookAuthor ) {
43
- this .books .push ({title: bookTitle, author: bookAuthor})
44
- }
45
- }
43
+ this .books .push ({ title: bookTitle, author: bookAuthor });
44
+ },
45
+ },
46
46
};
47
47
</script >
48
48
Original file line number Diff line number Diff line change 1
1
<template >
2
- <li >{{book.title}} : {{book.author}}</li >
2
+ <li @click = " $emit('add-suggestion', book.title, book.author) " >{{book.title}} : {{book.author}}</li >
3
3
</template >
4
4
5
5
<script >
Original file line number Diff line number Diff line change 4
4
<ul >
5
5
<book-suggestion
6
6
v-for =" suggestion in suggestions"
7
- :key =' suggestion'
7
+ :key =' suggestion.id '
8
8
:book =' suggestion'
9
+ @add-suggestion =' appendSuggestion'
9
10
></book-suggestion >
10
11
</ul >
11
12
</div >
@@ -18,12 +19,12 @@ import BookSuggestion from './BookSuggestion';
18
19
export default {
19
20
name: ' BookSuggestions' ,
20
21
components: {
21
- BookSuggestion
22
+ BookSuggestion,
22
23
},
23
24
data () {
24
25
return {
25
26
suggestions: [],
26
- }
27
+ };
27
28
},
28
29
methods: {
29
30
fetchSuggestions () {
@@ -36,10 +37,12 @@ export default {
36
37
},
37
38
buildTopBooks (books ) {
38
39
books .forEach (({ title, author }) => {
39
- console .log (title, author);
40
- this .suggestions .push ({ title: title, author: author });
40
+ this .suggestions .push ({ title, author });
41
41
});
42
42
},
43
+ appendSuggestion (title , author ) {
44
+ this .$emit (' appendBook' , title, author);
45
+ },
43
46
},
44
47
beforeMount () {
45
48
this .fetchSuggestions ();
You can’t perform that action at this time.
0 commit comments