Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. <template>
  2. <div class="w-full h-full flex justify-center">
  3. <div class="w-4/5">
  4. <!-- <table class="w-full text-left mt-10 table-auto">
  5. <thead>
  6. <tr>
  7. <th class="w-2/5">Title</th>
  8. <th class="w-2/5">Slug</th>
  9. <th class="w-1/5">Date</th>
  10. </tr>
  11. </thead>
  12. <tbody>
  13. <tr v-for="article in articles" :key="article._id">
  14. <td>{{ article.title }}</td>
  15. <td>{{ article.content }}</td>
  16. <td>{{ new Date(article.createdAt).toISOString().split('T')[0] }}</td>
  17. </tr>
  18. </tbody>
  19. </table> -->
  20. <div class="w-full flex mt-10 mb-4 border-b">
  21. <div class="w-1/4">Title</div>
  22. <div class="w-1/4">Slug</div>
  23. <div class="w-1/4">Date</div>
  24. <div class="w-1/4">Action</div>
  25. </div>
  26. <div class="w-full flex mb-2" v-for="article in articles" :key="article._id">
  27. <div class="w-1/4">
  28. <button @click="getArticle(article._id)">{{ article.title }}</button>
  29. </div>
  30. <div class="w-1/4">{{ article.slug }}</div>
  31. <div class="w-1/4">{{ new Date(article.createdAt).toISOString().split('T')[0] }}</div>
  32. <div class="w-1/4">test</div>
  33. </div>
  34. </div>
  35. </div>
  36. </template>
  37.  
  38. <script>
  39. import EventBus from '../eventBus'
  40. import axios from 'axios'
  41.  
  42. export default {
  43. data() {
  44. return {
  45. articles: []
  46. }
  47. },
  48. props: ['token'],
  49. methods: {
  50. getArticle(id) {
  51. const payload = {
  52. id
  53. }
  54. EventBus.$emit('changePage', { page: 'edit-article' })
  55. EventBus.$emit('getArticle', payload)
  56. },
  57. fetchArticles() {
  58. axios({
  59. method: 'get',
  60. url: 'http://localhost:3000/articles',
  61. headers: {
  62. token: this.token
  63. }
  64. })
  65. .then(({ data }) => {
  66. // console.log(data)
  67. this.articles = data
  68. console.log(this.articles)
  69. })
  70. .catch(err => {
  71. console.log(err)
  72. })
  73. }
  74. // singleArticle(id) {
  75. // axios({
  76. // method: 'get',
  77. // url: `http://localhost:3000/articles/${id}`,
  78. // headers: {
  79. // token: this.token
  80. // }
  81. // })
  82. // .then(({ data }) => {
  83. // // console.log(data)
  84. // this.articles = data
  85. // console.log(this.articles)
  86. // })
  87. // .catch(err => {
  88. // console.log(err)
  89. // })
  90. // }
  91. },
  92. created() {
  93. this.fetchArticles()
  94. }
  95. }
  96. </script>
  97.  
  98. <style></style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement