zoukankan      html  css  js  c++  java
  • Centrifuge在vue中基础使用,soket通讯

    Centrifuge soket通讯前端使用
    这个是后端在使用这个插件,然后前端只要引入一个这个文件,就可以使用,文章使用的文件,地址下本文底部,可直接访问地址下载

    <template>
      <div>
        测试websoket
        <div>{{text}}</div>
        <button @click="Fncolos">关闭连接</button>
      </div>
    </template>
    
    <script>
    import Centrifuge from '@/assets/js/centrifuge.min.js'
    export default {
      data(){
        return{
          text:'--------',
          centrifuge:null
        };
      },
      methods:{
        FnwebS(){
          let that=this
          this.centrifuge = new Centrifuge("ws://192.168.0.16:8001/connection/websocket");
          const centrifuge=this.centrifuge
          // centrifuge.setToken("")
          console.log(centrifuge,'--------centrifuge');
          
    
          centrifuge.on('connect', function (ctx) {
              console.log("connected", ctx);
          });
    
          centrifuge.on('disconnect', function (ctx) {
              console.log("disconnected", ctx);
          });
    
    
          //订阅频道c1  频道不同 收到的信息不同
          centrifuge.subscribe("c1", function (ctx) {
            that.text=ctx.data.value;
            console.log(ctx,'--------shuju',that.text);
          });
    
          //连接
          centrifuge.connect();
          //关闭连接
          // this.centrifuge.disconnect()
        },
        Fncolos(){
          console.log(this.centrifuge);
          this.centrifuge.disconnect()
        }
      },
      mounted(){
        this.FnwebS()
      },
    
    }
    </script>
    
    <style>
    
    </style>
    

    https://blog-static.cnblogs.com/files/enhengenhengNymph/centrifuge.min.js

  • 相关阅读:
    对于js中原型的理解
    换行问题
    居中方法
    浮动清除
    js基础内容 原型与实例
    uniapp 吸顶 小demo
    uniapp 锚点滚动报错(h.push is not a function)
    uni-app 页面滚动到指定位置
    过滤后端返回的html文本标签
    uniapp 上拉加载
  • 原文地址:https://www.cnblogs.com/enhengenhengNymph/p/15608181.html
Copyright © 2011-2022 走看看