Base.vue 2.1 KB

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