Base.vue 2.2 KB

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