1.main.js
import VueSocketio from 'vue-socket.io';
Vue.use(new VueSocketio({
debug: true,
connection: 'http://xxxxxxxxxxx',
options: { 'transports': ['websocket']} //Optional options
}))
2.index.vue
<template>
<div>socket首页</div>
</template>
<script>
import Vue from 'vue';
import socket from 'vue-socket.io';
Vue.use(new socket({
debug: true,
connection: 'http://172.16.8.61:5000/websocket/monitor/detail',
options: { 'transports': ['websocket']} //Optional options
}))
export default {
name: "Socket",
sockets: {
connect(){
window.console.log('socket连接成功');
},
response(data){
window.console.log(data,'后台返回数据');
}
},
mounted() {
this.$socket.emit('monitor',{'satellite_id':'GS-1a'})
},
}
</script>
<style scoped>
</style>
网友评论