-
Notifications
You must be signed in to change notification settings - Fork 272
/
Home.vue
110 lines (107 loc) · 2.97 KB
/
Home.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
<template>
<div class="home">
<h4 style="margin-top:30px;margin-bottom:30px">Articles</h4>
<div>
<div class="articlesTable" style="line-height: 30px;">
<div class="articlesRow">
<div class="articlesCell">
📃 Title
</div>
<div class="articlesCell" style="width:200px">
🧑 Author
</div>
<div class="articlesCell" style="width:150px">
💬 Twitter
</div>
<div class="articlesCell" style="width:80px">
🅱 Blog
</div>
</div>
<div v-for="article in articles" :key="article.id" class="articlesRow">
<div class="articlesCell">
<b-link target="_blank" :href="article.url">{{ article.title }}</b-link>
</div>
<div class="articlesCell">
{{ article.authorName }}
</div>
<div class="articlesCell">
<b-link v-if="article.authorTwitter != ''" target="_blank" :href="'https://twitter.com/' + article.authorTwitter">{{ article.authorTwitter }}</b-link>
</div>
<div class="articlesCell">
<b-link v-if="article.authorBlog != ''" target="_blank" :href="article.authorBlog">Blog</b-link>
</div>
</div>
</div>
</div>
<div style="margin-top:30px" v-if="(articles.length == 0) && (loading == false) && (error == '')">
<div>There are no articles</div>
</div>
<div style="margin-top:30px" v-if="error != ''">
<div>Articles could not be read</div>
<div>{{ error }}</div>
<div>{{ webApiUrl }}</div>
</div>
<b-spinner v-if="loading == true" label="Loading ..."/>
</div>
</template>
<script>
import axios from "axios";
export default {
name: "Home",
data() {
return {
webApiUrl: this.$store.state.endpoints.api + "articles",
articles: [],
loading: false,
error: ""
};
},
mounted() {
this.readArticles();
var source = new EventSource(this.$store.state.endpoints.api + "server-sent-events");
let that = this;
source.onmessage = function (event) {
that.readArticles();
};
},
methods: {
readArticles() {
this.loading = true;
const axiosService = axios.create({
timeout: 5000,
headers: {
"Content-Type": "application/json"
}
});
let that = this;
axiosService
.get(this.webApiUrl)
.then(function(response) {
that.articles = response.data;
that.loading = false;
that.error = "";
that.$store.commit("addArticles", response.data);
})
.catch(function(error) {
console.log(error);
that.loading = false;
that.error = error;
});
}
}
};
</script>
<style scoped>
.articlesTable {
display: table;
width:100%;
}
.articlesRow {
display: table-row;
}
.articlesCell {
max-width:100px;
display: table-cell;
vertical-align: top;
}
</style>