Vue websocket is encapsulated, and the component rendering completes the sending of data, which is faster than the websocket connection. How to solve it?

problem description

vue websocket is encapsulated, and the component rendering completes sending data, which is faster than the websocket connection. How to solve it?

the environmental background of the problems and what methods you have tried

   websocket,websocket.js. 
   created
   
   
   websocket
  

related codes

/ / Please paste the code text below (do not replace the code with pictures)

parent component

 created(){
        setInterval(() => {
            this.socketApi.registeSendSock(2)
        }, 8000)
    }

subcomponents

mounted(){
      this.$nextTick(() => { 
        var type = 5
        var sendData = new Object
        sendData.controlType = 11
        console.log(sendData)
        this.socketApi.controlsendSock(type,sendData)
       })
  },

what result do you expect? What is the error message actually seen?

how to send data after the connection is completed

Mar.23,2022

I do not understand. Generally, ws-based communications are based on callbacks. Messages are sent only in the callback parameters for which the link is successful. If you do not write it in the callback, the phenomenon described in your question may occur.


the parent component passes a status value or timestamp to the child component: when the status or timestamp is sent to the child component after the websocket connection, the child component listens for this value. Once modified, send the updated request to


if the whole project is based on websocket communication, you can get the connect callback to re-instantiate the project

after the connection is successful.
Menu