Guest User

Untitled

a guest
Jan 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. data = {
  2. title: 'Comment App',
  3. comments: [],
  4. comment: "",
  5. username: "",
  6. }
  7.  
  8. app = new Vue({
  9. el: '#app',
  10. data: data,
  11. methods: {
  12. getComments: function(){
  13. fetch('/get/comments.json')
  14. .then(response => response.json())
  15. .then(response => this.comments = response)
  16. },
  17. setComments: function(){
  18. fetch(`/set/comment?username=${this.username}&body=${this.comment}`)
  19.  
  20. // reset the comment
  21. this.resetInput()
  22.  
  23. // update the comment
  24. this.getComments()
  25. },
  26. removeComment: function(id, index){
  27. fetch(`/remove/comment/${id}`)
  28.  
  29. // delete manual
  30. this.comments.splice(index, 1)
  31.  
  32. // update the comment
  33. this.getComments()
  34. },
  35. resetInput: function(){
  36. this.comment = ''
  37. this.username = ''
  38. }
  39. },
  40. });
  41.  
  42. // init
  43. app.getComments();
Add Comment
Please, Sign In to add comment