Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

79 rindas
2.2KB

  1. <template>
  2. <div class="sm:flex items-center px-6 py-4">
  3. <div class="text-center sm:text-left sm:flex-grow">
  4. <div class="mb-4">
  5. <p class="flex flex-col sm:flex-row border-b border-2px py-4">
  6. <span class="flex-1 text-xl font-bold leading-tight ">Recent Projects</span>
  7. <span class="flex-none text-sm leading-tight text-grey-dark">
  8. <span @click="changePage(-1)" :class="{'line-through': is_first_page, 'cursor-pointer': !is_first_page}">prev</span>
  9. /
  10. <span @click="changePage(1)" :class="{'line-through': is_last_page, 'cursor-pointer': !is_last_page}">next</span>
  11. </span>
  12. </p>
  13. </div>
  14. <div>
  15. <!-- {{posts}} -->
  16. <div v-for="project in posts" v-bind:key="project.id" @click="redirect_href(project.link)" class="flex group cursor-pointer hover:text-white hover:bg-indigo p-4">
  17. <p class="flex-1 text-lg mb-1 group-hover:text-white " v-html="project.title.rendered"></p>
  18. <fa-layers full-width class="fa flex-none align-middle ml-2">
  19. <fa :icon="fas.faArrowCircleRight"/>
  20. </fa-layers>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. import { fas } from '@fortawesome/free-solid-svg-icons'
  28. export default {
  29. mounted() {
  30. this.fetchPosts()
  31. },
  32. methods: {
  33. async fetchPosts() {
  34. const posts = await this.$wp.posts().categories(21).perPage(8).page(this.current_page)
  35. this.posts = posts
  36. this.total_pages = posts._paging.totalPages
  37. },
  38. redirect_href: function (url) {
  39. window.open(url, '_blank');
  40. },
  41. changePage: function (p) {
  42. var newPage = this.current_page + p
  43. if (newPage >= 1 && newPage <= this.total_pages) {
  44. this.current_page = newPage
  45. this.fetchPosts()
  46. }
  47. },
  48. },
  49. data () {
  50. return {
  51. current_page: 1,
  52. total_pages: 1,
  53. posts: [
  54. {
  55. id: 0,
  56. title: {
  57. rendered: "Loading..."
  58. }
  59. }
  60. ]
  61. }
  62. },
  63. computed: {
  64. fas () {
  65. return fas
  66. },
  67. is_first_page() {
  68. return this.current_page == 1
  69. },
  70. is_last_page() {
  71. return this.current_page == this.total_pages
  72. }
  73. }
  74. }
  75. </script>