Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
</v-card-subtitle>
<v-card-title
class="subtitle-2 text-capitalize font-weight-bold title--text text-left mt-1 py-1"
@click="() => redirect(book.title)"
>
{{ book.title }}
</v-card-title>
Expand All @@ -81,6 +82,9 @@ export default {
fetchBook() {
this.$store.dispatch('book/fetchBook')
},
redirect(title) {
return this.$router.push(`/products/${title}`)
},
},
}
</script>
Expand Down
8 changes: 8 additions & 0 deletions pages/products/_bookname.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@
<script>
export default {
setup() {},
computed: {
bookTitle() {
return this.$route.params.bookname
},
},
mounted() {
this.$store.dispatch('book/fetchBookByTitle', this.bookTitle)
},
}
</script>
29 changes: 29 additions & 0 deletions store/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const state = () => ({
listBook: [],
listHomeBook: [],
listAuthor: [],
bookDetail: {},
})

const mutations = {
Expand All @@ -16,6 +17,9 @@ const mutations = {
setListAuthor(state, param) {
state.listAuthor = param
},
setBookDetail(state, param) {
state.setBookDetail = param
},
}

const actions = {
Expand Down Expand Up @@ -61,6 +65,31 @@ const actions = {
})
store.commit('setListAuthor', response.data.book)
},
async fetchBookByTitle(store, title) {
const response = await this.app.apolloProvider.defaultClient.query({
query: gql`
query MyQuery($title: String!) {
book(where: { title: { _eq: $title } }) {
author
image
slug
title
detail {
category
country
description
language
page_count
publisher
release_date
}
}
}
`,
variables: { title },
})
store.commit('setBookDetail', response.data.book)
},
}

export default { state, mutations, actions }