this.$socket.emit('sha','text')
socket.on('sha',data => {
console.log(data)
socket.emit('sha', data)
})
this.$socket.on('sha', data=>{
console.log(data)
this.str = data
})

群聊就不必
私聊多了一层监听与触发事件的转发

<input v-model="text" type="text" /> //选择私聊对象
<button @tap="info">发送</button>
this.$socket.emit('info',{type: this.text, msg: 'hello ya'}) //触发事件
socket.on('info', data => {//监听发送 信息包含特定对象 text
console.log(data)
socket.broadcast.emit(data.type, data.msg) //触发特定对象接收事件
})
onLoad(route) {
this.b = route.name // 加载获取特定用户
this.getb()
},
getb () {
this.$socket.on(this.b, (data) => {//监听发送 获取特定对象 发送的信息
console.log(data)
})
}