useStomp
STOMP 协议 WebSocket 连接 Composable。
使用方式
typescript
import { useStomp } from '@/composables'
const { connect, subscribe, send, disconnect } = useStomp({
brokerURL: 'ws://localhost:8080/ws'
})
// 连接
connect()
// 订阅主题
subscribe('/topic/messages', (message) => {
console.log('收到消息:', message.body)
})
// 发送消息
send('/app/message', { text: 'Hello' })
// 断开连接
disconnect()API
| 名称 | 类型 | 说明 |
|---|---|---|
| connect | () => void | 连接 WebSocket |
| subscribe | (destination, callback) => void | 订阅主题 |
| send | (destination, body) => void | 发送消息 |
| disconnect | () => void | 断开连接 |
