Vue.js eliminates websocket duplicate subscriptions

On the a page of

vue.js, there is an a function that subscribes to websocket. Switch to another page and then switch back. Because the a function of a page is executed in mounted, it subscribes again, causing the client to receive duplicate messages. However, the requirement is that you cannot unsubscribe when you leave page a, so is there any way to make it not repeat subscriptions?


1. When you leave the page, send a message to the server. You need to negotiate with the backend to unsubscribe.
2. When you leave the page, ws has a close () method that you can call.


localStorage defines variables. Every time you open this page, first determine whether there is a value. If there is no value, connect socket and store the value. If you have a value, directly return ah
in `

.
mounted ()  {
    if ( !localStorage.getItem('aaa') ) {
        this.socket();
        localStorage.setItem('sss', 'aaa')
    }
}

`

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e54263-59815.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e54263-59815.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?