uni-app中使用websocket

APP.vue

onLaunch: function() {
    uni.connectSocket({
        url: 'ws://xxxx',
        success: () => {
            console.log('websocket连接成功!');
        },
        fail: (err) => {
            console.log(err)
        },
        complete: () => {}
    });
}

任意vue组件

uni.onSocketMessage((res) => {
    console.log('收到服务器内容:' + res.data);
});

你可能感兴趣的:(uni-app中使用websocket)