美文网首页
vue使用socket.io长连接

vue使用socket.io长连接

作者: 小北呀_ | 来源:发表于2021-12-22 21:36 被阅读0次

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>

相关文章

网友评论

      本文标题:vue使用socket.io长连接

      本文链接:https://www.haomeiwen.com/subject/aflaghtx.html