Posts.vue 842 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <section v-if="opened != null">
  3. <h2>{{ opened.title }}</h2>
  4. <p>{{ opened.body }}</p>
  5. <span
  6. @click="closePost()"
  7. >
  8. close</span>
  9. </section>
  10. <ul v-else>
  11. <li
  12. v-for="post in posts"
  13. :key="post.id"
  14. >
  15. <h2>
  16. <a
  17. @click="openPost(post)"
  18. >
  19. {{ post.title }}</a></h2>
  20. </li>
  21. </ul>
  22. </template>
  23. <script>
  24. // import store from './store'
  25. // import datarest from 'components/data/datarest'
  26. import { mapState, mapActions } from 'vuex'
  27. // import { mapState } from 'vuex'
  28. export default {
  29. computed: mapState({
  30. opened: state => state.posts.opened,
  31. posts: state => state.posts.all
  32. }),
  33. methods: mapActions('posts', [
  34. 'openPost',
  35. 'closePost'
  36. ]),
  37. created () {
  38. this.$store.dispatch('posts/getAllPosts')
  39. }
  40. }
  41. </script>