How to solve the failure of using native websocket connection in vue?

failed to connect using native websocket in vue

< template >

<button @click="websocketonmessage()"></button>

< / template >

< script >

export default {

data () {
    return {
        websock:null
    };
},
methods: {
    // webscoket
    initWebSocket(){
        //websocket
        const wsurl = "";
        this.websock = new WebSocket(wsurl);
        this.websock.onopen = this.websocketonopen;

this.websock.onerror = this.websocketonerror;
this.websock.onmessage = this.websocketonmessage;

        this.websocket = this.websocket;
        this.websock.onclose = this.websocketclose;
    },
    websocket(){
        this.initWebSocket();
    },
    websocketonopen(e){
        console.log("WebSocket",e);
    },
    websocketonerror(e) { //

console.log ("connection error", e);
},

    websocketonmessage(res){
        console.log("",res.data);
    },
    websocketclose(e){
        console.log("",e)
    },
},
created () {
    this.initWebSocket();
},
destroyed(){
    this.websocketclose();
}

}
< / script >

clipboard.png

clipboard.png

clipboard.png

Sep.07,2021

this is that the server is not connected, and it has nothing to do with your code. See if the address is written correctly


is the reason why hosts is not configured. It has been solved!

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-1e50de8-4d482.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-1e50de8-4d482.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?