From 7ef65940eef485d77ae5e7eb4bb6fbb1e431dd71 Mon Sep 17 00:00:00 2001 From: Bastien Wirtz Date: Sun, 28 Jun 2020 18:31:42 -0700 Subject: Fix dynamic message override. --- src/components/Message.vue | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/components/Message.vue b/src/components/Message.vue index fcb0fbb..2c3df40 100644 --- a/src/components/Message.vue +++ b/src/components/Message.vue @@ -1,9 +1,9 @@ @@ -13,19 +13,25 @@ export default { props: { item: Object, }, - created: function () { + data: function () { + return { + show: false, + message: {}, + }; + }, + created: async function () { // Look for a new message if an endpoint is provided. - let that = this; + this.message = Object.assign({}, this.item); if (this.item && this.item.url) { - this.getMessage(this.item.url).then(function (message) { - // keep the original config value if no value is provided by the endpoint - for (const prop of ["title", "style", "content"]) { - if (prop in message && message[prop] !== null) { - that.item[prop] = message[prop]; - } + const fetchedMessage = await this.getMessage(this.item.url); + // keep the original config value if no value is provided by the endpoint + for (const prop of ["title", "style", "content"]) { + if (prop in fetchedMessage && fetchedMessage[prop] !== null) { + this.message[prop] = fetchedMessage[prop]; } - }); + } } + this.show = this.message.title || this.message.content; }, methods: { getMessage: function (url) { -- cgit v1.2.3