[Vuejs]-How to place server action listeners in a vuejs project?

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

Leave a comment