Base.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <div id="Base">
  3. <h1 class="page-title">{{ pagetitle }}</h1>
  4. <aside class="search-info">
  5. {{ searchinfos }}
  6. </aside>
  7. <div class="results">
  8. <ul>
  9. <li v-for="item in items" v-bind:key="item.nid">
  10. <Card :item="item"/>
  11. </li>
  12. </ul>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. import Card from 'vuejs/components/Content/Card'
  18. import { mapState, mapActions } from 'vuex'
  19. export default {
  20. name: "Base",
  21. data() {
  22. return {
  23. pagetitle:"Base",
  24. // searchinfos: null
  25. }
  26. },
  27. computed: {
  28. ...mapState({
  29. items: state => state.Search.items,
  30. searchinfos: state => state.Search.infos
  31. })
  32. },
  33. methods: {
  34. ...mapActions({
  35. newSearch: 'Search/newSearch'
  36. })
  37. },
  38. created() {
  39. // at first page load or first route entering launch a search if params exists in url query
  40. console.log('Base created() location',window.location);
  41. let params = new URLSearchParams(window.location.search)
  42. if(params.has('keys') || params.has('term')){
  43. this.$store.commit('Search/setKeys', params.get('keys'))
  44. this.$store.commit('Search/setTerm', params.get('term'))
  45. this.pagetitle = params.get('keys')
  46. this.newSearch()
  47. }
  48. },
  49. beforeRouteUpdate (to, from, next) {
  50. // when query change launch a new search
  51. console.log('Base beforeRouteUpdate', to, from, next);
  52. this.$store.commit('Search/setKeys', to.query.keys)
  53. this.$store.commit('Search/setTerm', to.query.term)
  54. this.pagetitle = to.query.keys
  55. this.newSearch()
  56. next()
  57. },
  58. components: {
  59. Card
  60. }
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. </style>