-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathEventList.vue
113 lines (101 loc) · 2.22 KB
/
EventList.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<script setup>
import { ref, onMounted, computed, watchEffect, defineProps } from "vue";
import EventCard from "@/components/EventCard.vue";
import EventService from "@/services/EventService.js";
import { useRouter } from "vue-router";
const props = defineProps(["page"]);
const router = useRouter();
const events = ref(null);
const totalEvents = ref(0);
const events = ref(null);
const totalEvents = ref(0);
const page = computed(() => props.page);
const page = computed(() => props.page);
const hasNextPage = computed(() => {
const totalPages = Math.ceil(totalEvents.value / 2);
return page.value < totalPages;
});
const hasNextPage = computed(() => {
const totalPages = Math.ceil(totalEvents.value / 2);
return page.value < totalPages;
});
onMounted(() => {
watchEffect(() => {
events.value = null;
EventService.getEvents(2, page.value)
.then((response) => {
events.value = response.data;
totalEvents.value = response.headers["x-total-count"];
})
.catch(() => {
router.push({ name: "NetworkError" });
});
});
});
</script>
<template>
<div>
<h1>Events for Good</h1>
<div class="events">
<EventCard v-for="event in events" :key="event.id" :event="event" />
<div class="pagination">
<router-link
id="page-prev"
:to="{ name: 'EventList', query: { page: page - 1 } }"
rel="prev"
v-if="page != 1"
>< Previous</router-link
>
<router-link
id="page-next"
:to="{ name: 'EventList', query: { page: page + 1 } }"
rel="next"
v-if="hasNextPage"
>Next ></router-link
>
</div>
</div>
</div>
</template>
<style scoped>
.events {
display: flex;
flex-direction: column;
align-items: center;
}
.pagination {
display: flex;
width: 290px;
}
.pagination a {
flex: 1;
text-decoration: none;
color: #2c3e50;
}
.events {
display: flex;
flex-direction: column;
align-items: center;
}
.pagination {
display: flex;
width: 290px;
}
.pagination a {
flex: 1;
text-decoration: none;
color: #2c3e50;
}
#page-prev {
text-align: left;
}
#page-prev {
text-align: left;
}
#page-next {
text-align: right;
}
#page-next {
text-align: right;
}
</style>