Base.vue 1.3 KB

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