在 vue 中使用 WebSocket
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<h1>{{ res }}</h1>
</div>
</template> <script>
export default {
name: 'ws',
data () {
return {
msg: '',
res: {},
lot_id: '000',
ws: null,
wsurl: ''
}
},
created () {
this.initws()
},
mounted () {
this.runws()
},
methods: {
runws () {
let content = 'source=client&lots=' + this.lot_id
if (this.ws.readyState === this.ws.OPEN) {
this.sendmessage(content)
} else if (this.ws.readyState === this.ws.CONNECTING) {
let that = this
setTimeout(function () {
that.sendmessage(content)
}, 300)
} else {
this.initws()
let that = this
setTimeout(function () {
that.sendmessage(content)
}, 500)
}
},
initws () {
this.ws = new WebSocket(this.wsurl)
this.ws.onmessage = this.getmessage
},
getmessage (e) {
this.res = JSON.parse(e.data)
},
sendmessage (content) {
this.ws.send(content)
}
}
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped> </style>
在 vue 中使用 WebSocket的更多相关文章
- 解决在VUE中绑定WebSocket事件无法传值的问题
this.webSocket.onerror =(env)=>{ this.onError(env) }; https://jsfiddle.net/dko6g9a4/1/
- vue中开发webSocket
先安装 sockjs-client 和 stompjs npm install sockjs-client npm install stompjs <template> <div&g ...
- Vue中使用websocket
<template> <div class="test">websocket demo</div></template> < ...
- 在vue中如何使用WebSocket 以及nginx代理如何配置WebSocket
WebSocket WebSocket是一种网络传输协议,可在单个TCP连接上进行全双工通信.浏览器和服务器只需要完成一次握手,两者之间就可以创建持久性的连接,并进行双向数据传输. 浏览器支持情况 现 ...
- vue中websoket的使用
首先安装npm install --save websocket-heartbeat-js@^1.0.7 在main.js中 引入并挂载全局方法 import WebsocketHeartbeat ...
- vue项目使用websocket做聊天项目总结
一.首先我们先了解一下websocket的使用: 1.创建websocket const ws = new WebSocket("ws://192.168.31.136:9998/ws&qu ...
- vue中解决chrome浏览器自动播放音频 和MP3语音打包到线上
一.vue中解决chrome浏览器自动播放音频 需求 有新订单的时候,页面自动语音提示和弹出提示框: 问题 chrome浏览器在18年4月起,就在桌面浏览器全面禁止了音视频的自动播放功能.严格地来说, ...
- vue - Vue中的ajax
只有在ajax才能找回一点点主场了,vue中的ajax一天整完,内容还行,主要是对axios的运用. 明天按理说要开始vuex了,这个从来都是只耳闻没有眼见过,明天来看看看看是个什么神奇的东西. 一. ...
- 【C#】MVC项目中搭建WebSocket服务器
前言 因为项目需要,前端页面中需要不断向后台请求获取一个及一个以上的状态值.最初的方案是为每个状态值请求都建立一个定时器循环定时发起Ajax请求,结果显而 易见.在HTTP1.1协议中,同一客户端浏览 ...
随机推荐
- 【Python】使用Selenium实现淘宝抢单
最近,小明为了达成小姐姐的愿望,在某宝买到心仪的宝贝,再加上又迷上了python,就通过python轻而易举地实现了(个人声明:对Java来说,这并不是背叛). 需求分析&前期准备 需求其实很 ...
- linux网络编程-socket(36)
进程是程序的一次动态执行的过程,进程是短暂的. 一个程序可以对应多个进程,可以打开多个记事本程序,存在多个进程. 线程是进程内部中的控制序列,一个进程至少有一个执行线路. 一个进程可以存在多个线程
- 入门大数据---安装ClouderaManager,CDH和Impala,Hue,oozie等服务
1.要求和支持的版本 (PS:我使用的环境,都用加粗标识了.) 1.1 支持的操作系统版本 操作系统 版本 RHEL/CentOS/OL with RHCK kernel 7.6, 7.5, 7.4, ...
- 如何使用ABP进行软件开发之基础概览
ABP框架简述 1)简介 在.NET众多的技术框架中,ABP框架(本系列中指aspnetboilerplate项目)以其独特的魅力吸引了一群优秀开发者广泛的使用. 在该框架的赋能之下,开发者可根据需求 ...
- npm tip: go to the package's home page
exec the following order: --- npm home <package name>
- Android 伤敌一千自损八百之萤石摄像头集成(一)
最近忙着修改萤石摄像头C3型号开头的设备添加 本来不是很复杂的事情. , 现在我感觉我入魔了 总感觉这是个小人 螺丝口是眼睛 插入SD卡的事鼻子嘴 接信号的事手 怎么看怎么像愤怒的小人 总结,先看一下 ...
- day02小程序配置
附上微信小程序开发文档的网址:https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html 学技术 ...
- 常用的rac搭建相关
平时自己测试环境搭建用,部分参数是不规范的. 生产请按照官方文档或者公司标准化文档来做. 共享硬盘: disk.locking = "FALSE" diskLib.dataCach ...
- 03.springboot 整合RabbitMQ
1.引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- 14.刚体组件Rigidbody
刚体组件是物理类组件,添加有刚体组件的物体,会像现实生活中的物体一样有重力.会下落.能碰撞. 给物体添加刚体: 选中游戏物体->菜单Component->Physics->Rigid ...