2๐
โ
putting in mounted() or created() will make it get called over and
over again.
this.socket.on
is a "socket version" of document.addEventListener
(docs) so, you will set a function (callback) that will be executed when a certain event occurs (receive-message
in your case). Depending on what createMessageHtmlElement
actually does, you can put this.socket.on
in either created()
or mounted()
.
Assuming you have a simple app, probably the best place to do that is App.vue
since the listener is going to be registered when the App.vue
is registered (Vue lifecycle)
๐คZarko
Source:stackexchange.com