Base.vue 2.4 KB

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