增加Websocketclient控件
This commit is contained in:
4
Web/Vue/WebSocketClient/.npmrc
Normal file
4
Web/Vue/WebSocketClient/.npmrc
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
registry=http://47.111.181.23:8081/repository/npm-releases/
|
||||||
|
//47.111.181.23:8081/repository/npm-releases/:_auth=YWRtaW46YWRtaW4=
|
||||||
|
always-auth=true
|
||||||
|
email=admin@example.com
|
||||||
59
Web/Vue/WebSocketClient/README.md
Normal file
59
Web/Vue/WebSocketClient/README.md
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
# WebSocketClient
|
||||||
|
|
||||||
|
Vue 3 的 WebSocket 客户端组件,提供连接/断开、自动重连、消息发送与事件回调。
|
||||||
|
|
||||||
|
## 安装
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm i com.joyd.websocket-client --registry=http://47.111.181.23:8081/repository/npm-public/
|
||||||
|
```
|
||||||
|
|
||||||
|
> 发布在私有仓库 `npm-releases`,对外读取建议通过组仓库 `npm-public`。
|
||||||
|
|
||||||
|
## 使用
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { createApp } from 'vue'
|
||||||
|
import App from './App.vue'
|
||||||
|
|
||||||
|
// 按需导入
|
||||||
|
import { WebSocketClient } from 'com.joyd.websocket-client'
|
||||||
|
|
||||||
|
createApp(App).component('WebSocketClient', WebSocketClient).mount('#app')
|
||||||
|
```
|
||||||
|
|
||||||
|
或在 SFC 中:
|
||||||
|
|
||||||
|
```vue
|
||||||
|
<script setup>
|
||||||
|
import { WebSocketClient } from 'com.joyd.websocket-client'
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<WebSocketClient url="ws://localhost:3000/ws" @message="onMsg" />
|
||||||
|
</template>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Props
|
||||||
|
- `url`: WebSocket 服务端地址。
|
||||||
|
- `protocols`: 子协议,数组或字符串。
|
||||||
|
- `autoReconnect`: 是否自动重连(默认 `true`)。
|
||||||
|
- `reconnectInterval`: 重连间隔毫秒(默认 `3000`)。
|
||||||
|
- `maxReconnectAttempts`: 最大重连次数(默认无限)。
|
||||||
|
|
||||||
|
## 事件
|
||||||
|
- `connect`: 连接成功触发。
|
||||||
|
- `disconnect`: 连接关闭触发。
|
||||||
|
- `message`: 收到消息触发,`(payload: any)`。
|
||||||
|
- `error`: 发生错误触发。
|
||||||
|
|
||||||
|
## 发布说明
|
||||||
|
已设置 `publishConfig.registry` 指向:
|
||||||
|
`http://47.111.181.23:8081/repository/npm-releases/`
|
||||||
|
|
||||||
|
如需发布:
|
||||||
|
```bash
|
||||||
|
npm publish
|
||||||
|
```
|
||||||
|
|
||||||
|
需要在本目录配置 `.npmrc` 或使用 `npm adduser --registry=<repo>` 完成鉴权。
|
||||||
4
Web/Vue/WebSocketClient/index.js
Normal file
4
Web/Vue/WebSocketClient/index.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import WebSocketClient from './WebSocketClient.vue'
|
||||||
|
|
||||||
|
export { WebSocketClient }
|
||||||
|
export default WebSocketClient
|
||||||
BIN
Web/Vue/WebSocketClient/joyd.web.vue.websocket-client-1.0.0.tgz
Normal file
BIN
Web/Vue/WebSocketClient/joyd.web.vue.websocket-client-1.0.0.tgz
Normal file
Binary file not shown.
24
Web/Vue/WebSocketClient/package.json
Normal file
24
Web/Vue/WebSocketClient/package.json
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"name": "joyd.web.vue.websocket-client",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Vue 3 WebSocket 客户端组件(SFC)",
|
||||||
|
"type": "module",
|
||||||
|
"main": "index.js",
|
||||||
|
"files": [
|
||||||
|
"WebSocketClient.vue",
|
||||||
|
"index.js",
|
||||||
|
"README.md"
|
||||||
|
],
|
||||||
|
"peerDependencies": {
|
||||||
|
"vue": ">=3.3.0"
|
||||||
|
},
|
||||||
|
"keywords": ["vue3", "websocket", "component", "joyd"],
|
||||||
|
"author": "JoyD",
|
||||||
|
"license": "MIT",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"publishConfig": {
|
||||||
|
"registry": "http://47.111.181.23:8081/repository/npm-releases/"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user