Skip to content

Commit 8d9c4ef

Browse files
author
Hampton Paulk
committed
add remote calls
1 parent fa32a0b commit 8d9c4ef

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

src/components/BookForm.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
export default {
1111
name: 'BookForm',
1212
props: ['books'],
13-
data () {
13+
data() {
1414
return {
1515
bookTitle: '',
1616
bookAuthor: '',
17-
}
17+
};
1818
},
1919
methods: {
20-
bookSubmit (bookTitle, bookAuthor){
21-
this.$emit('addBook', bookTitle, bookAuthor)
22-
}
20+
bookSubmit(bookTitle, bookAuthor) {
21+
this.$emit('addBook', bookTitle, bookAuthor);
2322
},
23+
},
2424
};
2525
</script>
2626

src/components/BookList.vue

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<ul>
55
<book-item
66
v-for='book in books'
7-
:key='book'
7+
:key='book.id'
88
:book='book'
99
></book-item>
1010
</ul>
1111
<br>
1212
<book-form @addBook='appendBook'></book-form>
1313
<br><hr>
14-
<book-suggestions></book-suggestions>
14+
<book-suggestions @appendBook='appendBook'></book-suggestions>
1515
</div>
1616
</template>
1717

@@ -40,9 +40,9 @@ export default {
4040
},
4141
methods: {
4242
appendBook(bookTitle, bookAuthor) {
43-
this.books.push({title: bookTitle, author: bookAuthor})
44-
}
45-
}
43+
this.books.push({ title: bookTitle, author: bookAuthor });
44+
},
45+
},
4646
};
4747
</script>
4848

src/components/BookSuggestion.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<li>{{book.title}} : {{book.author}}</li>
2+
<li @click="$emit('add-suggestion', book.title, book.author)">{{book.title}} : {{book.author}}</li>
33
</template>
44

55
<script>

src/components/BookSuggestions.vue

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
<ul>
55
<book-suggestion
66
v-for="suggestion in suggestions"
7-
:key='suggestion'
7+
:key='suggestion.id'
88
:book='suggestion'
9+
@add-suggestion='appendSuggestion'
910
></book-suggestion>
1011
</ul>
1112
</div>
@@ -18,12 +19,12 @@ import BookSuggestion from './BookSuggestion';
1819
export default {
1920
name: 'BookSuggestions',
2021
components: {
21-
BookSuggestion
22+
BookSuggestion,
2223
},
2324
data() {
2425
return {
2526
suggestions: [],
26-
}
27+
};
2728
},
2829
methods: {
2930
fetchSuggestions() {
@@ -36,10 +37,12 @@ export default {
3637
},
3738
buildTopBooks(books) {
3839
books.forEach(({ title, author }) => {
39-
console.log(title, author);
40-
this.suggestions.push({ title: title, author: author });
40+
this.suggestions.push({ title, author });
4141
});
4242
},
43+
appendSuggestion(title, author) {
44+
this.$emit('appendBook', title, author);
45+
},
4346
},
4447
beforeMount() {
4548
this.fetchSuggestions();

0 commit comments

Comments
 (0)