diff --git a/pages/index.vue b/pages/index.vue index 1ff43b8..0a02e83 100644 --- a/pages/index.vue +++ b/pages/index.vue @@ -57,6 +57,7 @@ {{ book.title }} @@ -81,6 +82,9 @@ export default { fetchBook() { this.$store.dispatch('book/fetchBook') }, + redirect(title) { + return this.$router.push(`/products/${title}`) + }, }, } diff --git a/pages/products/_bookname.vue b/pages/products/_bookname.vue index 8fad6f3..2e3d6de 100644 --- a/pages/products/_bookname.vue +++ b/pages/products/_bookname.vue @@ -4,5 +4,13 @@ diff --git a/store/book.js b/store/book.js index 241ca6a..3b74376 100644 --- a/store/book.js +++ b/store/book.js @@ -4,6 +4,7 @@ const state = () => ({ listBook: [], listHomeBook: [], listAuthor: [], + bookDetail: {}, }) const mutations = { @@ -16,6 +17,9 @@ const mutations = { setListAuthor(state, param) { state.listAuthor = param }, + setBookDetail(state, param) { + state.setBookDetail = param + }, } const actions = { @@ -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 }