diff options
author | Bastien Wirtz <bastien.wirtz@gmail.com> | 2020-05-25 15:07:03 -0700 |
---|---|---|
committer | Bastien Wirtz <bastien.wirtz@gmail.com> | 2020-05-25 15:07:03 -0700 |
commit | b9c5fcf085bed9c6100283133531b36bfbb06cf0 (patch) | |
tree | 7baa4d16c9d6c06745727c7c273065a29b8fc1d7 /src/components/Message.vue | |
parent | ab7ac44c191e3b7dea696e76b74097e23f73b18c (diff) | |
download | homer-b9c5fcf085bed9c6100283133531b36bfbb06cf0.tar.gz homer-b9c5fcf085bed9c6100283133531b36bfbb06cf0.tar.zst homer-b9c5fcf085bed9c6100283133531b36bfbb06cf0.zip |
Build system integration using vue-cli.
Diffstat (limited to 'src/components/Message.vue')
-rw-r--r-- | src/components/Message.vue | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/components/Message.vue b/src/components/Message.vue new file mode 100644 index 0000000..fcb0fbb --- /dev/null +++ b/src/components/Message.vue | |||
@@ -0,0 +1,41 @@ | |||
1 | <template> | ||
2 | <article v-if="item" class="message" :class="item.style"> | ||
3 | <div v-if="item.title" class="message-header"> | ||
4 | <p>{{ item.title }}</p> | ||
5 | </div> | ||
6 | <div v-if="item.content" class="message-body" v-html="item.content"></div> | ||
7 | </article> | ||
8 | </template> | ||
9 | |||
10 | <script> | ||
11 | export default { | ||
12 | name: "Message", | ||
13 | props: { | ||
14 | item: Object, | ||
15 | }, | ||
16 | created: function () { | ||
17 | // Look for a new message if an endpoint is provided. | ||
18 | let that = this; | ||
19 | if (this.item && this.item.url) { | ||
20 | this.getMessage(this.item.url).then(function (message) { | ||
21 | // keep the original config value if no value is provided by the endpoint | ||
22 | for (const prop of ["title", "style", "content"]) { | ||
23 | if (prop in message && message[prop] !== null) { | ||
24 | that.item[prop] = message[prop]; | ||
25 | } | ||
26 | } | ||
27 | }); | ||
28 | } | ||
29 | }, | ||
30 | methods: { | ||
31 | getMessage: function (url) { | ||
32 | return fetch(url).then(function (response) { | ||
33 | if (response.status != 200) { | ||
34 | return; | ||
35 | } | ||
36 | return response.json(); | ||
37 | }); | ||
38 | }, | ||
39 | }, | ||
40 | }; | ||
41 | </script> | ||