Guest User

Untitled

a guest
Jun 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. <template>
  2. <div class="media-list media-list-hover media-list-divided">
  3. <comenatario-item v-for="comment in comments"
  4. :key="comment.id"
  5. :parent_comment="comment.id"
  6. :comment="comment"
  7. :author="comment.author"
  8. :post_id="comment.post_id"
  9. :auth="auth"
  10. :has_replies="comment.has_replies"
  11. :cant_replies="comment.total_replies"
  12. :data_confirm="data_confirm">
  13. </comenatario-item>
  14. </div>
  15. </template>
  16.  
  17. <script>
  18. export default {
  19. props: ["post_id", "loading_comments", "data_confirm", "auth"],
  20.  
  21. data() {
  22. return {
  23. comments: [],
  24. isLoading: false,
  25. endpoint: "/api/v1/posts/" + this.post_id + "/comments/"
  26. };
  27. },
  28.  
  29. mounted() {
  30. this.retrieveComments();
  31.  
  32. if (window.Echo) {
  33. Echo.channel("post." + this.post_id)
  34. .listen(".comment.posted", e => {this.addComment(e.comment)});
  35. }
  36.  
  37. Event.$on("added", comment => {
  38. this.addComment(comment);
  39. });
  40. },
  41.  
  42. methods: {
  43. retrieveComments() {
  44. this.isLoading = true;
  45.  
  46. axios.get(this.endpoint)
  47. .then(response => {
  48. this.comments.push(...response.data.data);
  49. this.isLoading = false;
  50. this.endpoint = response.data.links.next;
  51. })
  52. .catch(error => {
  53. console.log(error);
  54. this.isLoading = false;
  55. });
  56. },
  57.  
  58. addComment(comment) {
  59. this.comments.unshift(comment);
  60. }
  61. }
  62. }
  63. </script>
Add Comment
Please, Sign In to add comment