| | |
| | | <template> |
| | | <!-- <button v-on:click="send">测试发送</button> --> |
| | | <button @click="send()">测试发送</button> |
| | | |
| | | <div> |
| | | <button @click="send()">测试发送</button> |
| | | <button @click="ttt()">测试发送</button> |
| | | |
| | | </div> |
| | | |
| | | |
| | | |
| | | </template> |
| | | |
| | | <script> |
| | |
| | | messagepack: { |
| | | data: { taskname:"" } |
| | | }, |
| | | qqqq:{}, |
| | | queryInfo: { |
| | | data: "1", |
| | | pageSize: 10 |
| | |
| | | }, |
| | | created() { |
| | | this.init(); |
| | | |
| | | }, |
| | | methods: |
| | | { |
| | |
| | | socket.onmessage = function (msg) { |
| | | console.log("收到数据====" + msg.data) |
| | | |
| | | //let data = JSON.parse(msg.data) // 对收到的json数据进行解析, 类似这样的: {"users": [{"username": "zhang"},{ "username": "admin"}]} |
| | | |
| | | // 对收到的json数据进行解析, 类似这样的: {"users": [{"username": "zhang"},{ "username": "admin"}]} |
| | | this.qqqq= JSON.parse(msg.data); |
| | | console.log(this.qqqq); |
| | | }; |
| | | //关闭事件 |
| | | socket.onclose = function () { |
| | |
| | | send() { |
| | | this.messagepack.data = {taskname:"前端到后台"} ; |
| | | socket?.send(JSON.stringify(this.messagepack)); // 将组装好的json发送给服务端,由服务端进行转发 |
| | | } |
| | | }, |
| | | ttt() { |
| | | console.log(this.qqqq) |
| | | }, |
| | | |
| | | } |
| | | } |
| | | </script> |