Base.vue 1.7 KB

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