FlagCollection.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <section class="flag-collection">
  3. <h3>{{collection.name}}</h3>
  4. <ul v-if="loadedItems">
  5. <li
  6. v-for="item in loadedItems"
  7. :key="item.id"
  8. >{{item.attributes.title}}</li>
  9. </ul>
  10. <span v-else class="loading">Loading</span>
  11. </section>
  12. </template>
  13. <script>
  14. import { mapState, mapActions } from 'vuex'
  15. export default {
  16. name: "FlagCollection",
  17. props: ['collection'],
  18. data: () => ({
  19. loadedItems: false
  20. }),
  21. computed: {
  22. ...mapState({
  23. flagcolls: state => state.User.flagcolls
  24. // openedCollid: state => state.User.openedCollid
  25. })
  26. },
  27. // watch: {
  28. // flagcolls (newv, oldv) {
  29. // console.log('watching flagcolls');
  30. // if( typeof this.flagcolls[this.collection.id].loadedItems !== 'undefined' ) {
  31. // this.loadedItems = this.flagcolls[this.collection.id].loadedItems
  32. // }
  33. // }
  34. // },
  35. created() {
  36. this.unsubscribe = this.$store.subscribe((mutation, state) => {
  37. if (mutation.type === 'User/setLoadedCollItems') {
  38. this.loadedItems = state.User.flagcolls[this.collection.id].loadedItems
  39. }
  40. });
  41. },
  42. beforeDestroy() {
  43. this.unsubscribe()
  44. },
  45. // beforeMount () {
  46. // if (typeof this.flagcolls[collection.id].loadedItems === 'undefined') {
  47. // this.
  48. // }
  49. // },
  50. // methods: {
  51. // ...mapActions({
  52. // loadFlagCollItems: 'User/loadFlagCollItems'
  53. // })
  54. // }
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. </style>