Base.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.id">
  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. } else {
  69. // load default base page
  70. this.$store.commit('Search/setKeys', '')
  71. this.$store.commit('Search/setTerm', '')
  72. this.pagetitle = 'Base'
  73. this.newSearch()
  74. }
  75. },
  76. beforeRouteUpdate (to, from, next) {
  77. // when query change launch a new search
  78. console.log('Base beforeRouteUpdate', to, from, next)
  79. this.$store.commit('Search/setKeys', to.query.keys)
  80. this.$store.commit('Search/setTerm', to.query.term)
  81. this.pagetitle = to.query.keys
  82. this.newSearch()
  83. next()
  84. },
  85. components: {
  86. Card,
  87. CardThematique
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. </style>