2025-05-29 15:03:59 +08:00

5 lines
1.6 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{_ as x,c as f,e as n,m as s,f as o,j as w,w as m,o as a}from"./index-CrAWI0wi.js";const V={data(){return{url:"ws://127.0.0.1:8080/websocket/message",message:"",text_content:"",ws:null}},methods:{join(){const p=this.url;this.ws=new WebSocket(p);const t=this;this.ws.onopen=function(u){t.text_content=t.text_content+`已经打开连接!
`},this.ws.onmessage=function(u){t.text_content=u.data+`
`},this.ws.onclose=function(u){t.text_content=t.text_content+`已经关闭连接!
`}},exit(){this.ws&&(this.ws.close(),this.ws=null)},send(){this.ws?this.ws.send(this.message):alert("未连接到服务器")}}};function k(p,t,u,b,e,i){const r=w("el-input"),d=w("el-button");return a(),f("div",null,[n(r,{modelValue:e.url,"onUpdate:modelValue":t[0]||(t[0]=l=>e.url=l),type:"text",style:{width:"20%"}},null,8,["modelValue"]),t[6]||(t[6]=s("     ")),n(d,{onClick:i.join,type:"primary"},{default:m(()=>t[3]||(t[3]=[s("连接")])),_:1},8,["onClick"]),n(d,{onClick:i.exit,type:"danger"},{default:m(()=>t[4]||(t[4]=[s("断开")])),_:1},8,["onClick"]),t[7]||(t[7]=o("br",null,null,-1)),n(r,{type:"textarea",modelValue:e.message,"onUpdate:modelValue":t[1]||(t[1]=l=>e.message=l),rows:9},null,8,["modelValue"]),n(d,{type:"info",onClick:i.send},{default:m(()=>t[5]||(t[5]=[s("发送消息")])),_:1},8,["onClick"]),t[8]||(t[8]=o("br",null,null,-1)),t[9]||(t[9]=o("br",null,null,-1)),n(r,{type:"textarea",modelValue:e.text_content,"onUpdate:modelValue":t[2]||(t[2]=l=>e.text_content=l),rows:9},null,8,["modelValue"]),t[10]||(t[10]=s(" 返回内容 ")),t[11]||(t[11]=o("br",null,null,-1)),t[12]||(t[12]=o("br",null,null,-1))])}const C=x(V,[["render",k]]);export{C as default};