pnpm install
<!-- vue2 -->
pnpm -F web-socket-vue2 start
<!-- vue3 -->
pnpm -F web-socket-vue3 dev
<!-- 打包 -->
pnpm run build:rollup
<!-- Mac 上传到npm -->
pnpm run publishm:private <npm私服:服务器根据自己本地配置>
pnpm run publishm:public <npm公网>
<!-- Windows 上传到npm -->
pnpm run publishw:private <npm私服:服务器根据自己本地配置>
pnpm run publishw:public <npm公网>
入参 | 类型 | 是否必传 | 说明 |
---|---|---|---|
vueType | string | 必传 | 告诉插件是vue2 还是vue3。 只能传vue2 或者vue3 |
reconnectTimeout | number | 非必传 | 重新连接进入延迟时间 默认5s |
receiveMessageTimeout | number | 非必传 | 接收消息超时时间 默认10s |
reconnectTimes | number | 非必传 | 重新进入次数 默认3次 |
heartBeat | boolean | 非必传 | 是否发送心跳包 默认true |
reconnectInterval | number | 非必传 | 重新连接间隔 |
reconnectDelay | number | 非必传 | 重新进入延迟时间 |
reconnect | boolean | 非必传 | 是否定时重进入 |
发送给后端心跳包字段为:hearbeat
const app = createApp(App);
app.use(webSocketConnect, {
vueType: "vue3",
heartBeat: false
});
app.mount("#app");
插件注册后会往vue实例上挂在一个$ws的实例
- 1、创建:createWebSocket(wsUrl: string)
- 2、关闭连接:closeWebSocket()
- 3、发送数据:sendSock(agentData: any, callback: Function, key: string)
- 4、获取回调函数: setSockFn(key: string, callback: Function)
- 5、重新连接socket方法:reConnectWebSocket()