Base.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. data: () => ({
  19. }),
  20. computed: {
  21. ...mapState({
  22. items: state => state.Search.items
  23. })
  24. },
  25. methods: {
  26. ...mapActions({
  27. newSearch: 'Search/newSearch'
  28. })
  29. },
  30. created() {
  31. // laucnh a search if params exists in url query
  32. console.log('Base created() location',window.location);
  33. let params = new URLSearchParams(window.location.search)
  34. if(params.has('keys')){
  35. this.$store.commit('Search/setKeys', params.get('keys'))
  36. this.newSearch()
  37. }
  38. },
  39. // beforeRouteEnter (to, from, next) {
  40. // console.log('Base beforeRouteEnter');//, to, from, next);
  41. // next()
  42. // },
  43. beforeRouteUpdate (to, from, next) {
  44. console.log('Base beforeRouteUpdate', to, from, next);
  45. this.$store.commit('Search/setKeys', to.query.keys)
  46. this.$store.commit('Search/setTerm', to.query.term)
  47. this.newSearch()
  48. next()
  49. },
  50. components: {
  51. Card
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. </style>