Processing of websocket in vue

current projects use vue, and native websocket. After logging in to the business, I use a unified js file as the entry for processing websocket, including websocket creation, connection, and message processing. I thought the message I was dealing with was simple. Now I find that I need to use the websocket object of new at login in the component, and then I use vuex as the storage. But I"m worried that the business of vuex"s websocket fetched in the business component will override the onmessage method. It turns out that part of the business is written in the entry and about the onmessage method, but it is not possible to handle all the business in the js of the websocket entry. So it"s annoying. Ask whether writing the onmessage method in the component will overwrite the original, and do you have any experience or methods to deal with it?

Mar.18,2021

is there any good solution? if it is the same websock object from return, it will be overwritten


excuse me whether the problem has been solved, I am also the same problem


Does

mean that it will be overwritten repeatedly when other components use onmessage?
such as

A.vue
socket.onmessage= function(event){
 A.vue...
}

B.vue
socket.onmessage= function(event){
 B.vue...
}
Will

B overwrite A?
if this is the case, wouldn't it be nice to write onmessage as the same? The name of the event is given with the cooperation of the background.
socket.onmessage= function (event) {

 if(event.Name == 'A.vue'){
  ...
 }else if(event.Name = '..'){
  ...
 }

}
I don't know if I understand it correctly.


does the landlord have a solution? Share

Menu