Api call from component itself.

This commit is contained in:
2021-02-18 23:23:16 +01:00
parent 6e0b2b76fe
commit 710f276a9b

View File

@@ -9,32 +9,41 @@
</template> </template>
<script> <script>
import { historyByDate, historyAll } from '@/api' import { historyByDate, historyAll } from "@/api";
import { humanReadableDate } from "@/utils"; import { humanReadableDate } from "@/utils";
import Winners from '@/ui/Winners' import Winners from "@/ui/Winners";
export default { export default {
name: 'History page of prev lotteries', name: "History page of prev lotteries",
components: { Winners }, components: { Winners },
data() { data() {
return { return {
lotteries: [], lotteries: []
} };
},
methods: {
humanReadableDate: humanReadableDate
}, },
created() { created() {
const dateFromUrl = this.$route.params.date; const dateFromUrl = this.$route.params.date;
if (dateFromUrl !== undefined) if (dateFromUrl !== undefined) {
historyByDate(dateFromUrl) this.fetchHistoryByDate(dateFromUrl).then(history => (this.lotteries = [history]));
.then(history => this.lotteries = { "lottery": history }) } else {
else this.fetchHistory().then(history => (this.lotteries = history));
historyAll() }
.then(history => this.lotteries = history.lotteries) },
methods: {
humanReadableDate: humanReadableDate,
fetchHistory() {
return fetch("/api/history/by-date")
.then(resp => resp.json())
.then(response => response.lotteries);
},
fetchHistoryByDate(date) {
return fetch(`/api/history/by-date/${date}`)
.then(resp => resp.json())
.then(response => response);
} }
} }
};
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>