Added vuex as a store and an event bus.

This commit is contained in:
krzysiej
2022-06-13 15:17:02 +02:00
parent 5c154b740c
commit 8dbd63478d
8 changed files with 118 additions and 21 deletions

View File

@@ -1,12 +1,12 @@
<template>
<div>
<h1 v-if="searchTerm" v-html="'Book search: '+searchTerm"></h1>
<h1 v-if="searchTitle" v-html="'Book search: '+searchTitle"></h1>
<h1 v-else>Book list</h1>
</div>
</template>
<script>
import {EventBus} from "../event-bus";
import {mapState} from "vuex";
export default {
name: 'BookListingHeader',
@@ -15,14 +15,8 @@ export default {
searchTerm: null,
}
},
created() {
window.EventBus.$on('updateBookListingHeader', (data) => {
this.searchTerm = data.searchTerm;
});
computed: {
...mapState('booksmodule', ['searchTitle']),
},
mounted() {
const urlParams = new URLSearchParams(window.location.search);
this.searchTerm = urlParams.get('search') || "";
}
}
</script>