{"id":13536052,"url":"https://github.com/icebob/vue-websocket","last_synced_at":"2025-12-30T06:51:00.316Z","repository":{"id":65412479,"uuid":"73479603","full_name":"icebob/vue-websocket","owner":"icebob","description":"Simple websocket (socket.io) plugin for Vue.js","archived":true,"fork":false,"pushed_at":"2018-09-02T11:49:00.000Z","size":364,"stargazers_count":532,"open_issues_count":8,"forks_count":75,"subscribers_count":28,"default_branch":"master","last_synced_at":"2024-09-19T05:49:25.836Z","etag":null,"topics":["vue","vue-websocket","vuejs","websocket"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/icebob.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-11-11T13:24:55.000Z","updated_at":"2024-09-17T17:23:33.000Z","dependencies_parsed_at":"2023-01-22T08:05:38.371Z","dependency_job_id":null,"html_url":"https://github.com/icebob/vue-websocket","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icebob%2Fvue-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icebob%2Fvue-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icebob%2Fvue-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icebob%2Fvue-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icebob","download_url":"https://codeload.github.com/icebob/vue-websocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222795273,"owners_count":17038797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["vue","vue-websocket","vuejs","websocket"],"created_at":"2024-08-01T09:00:34.151Z","updated_at":"2025-12-15T01:15:19.663Z","avatar_url":"https://github.com/icebob.png","language":"JavaScript","funding_links":[],"categories":["实用库","Awesome Vue.js [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)","公用事业","Components \u0026 Libraries","Integrations","Utilities [🔝](#readme)","Utilities"],"sub_categories":["Libraries \u0026 Plugins","双向信息传输","Utilities","Miscellaneous","Web Sockets"],"readme":"# vue-websocket [![NPM version](https://img.shields.io/npm/v/vue-websocket.svg)](https://www.npmjs.com/package/vue-websocket)\n![VueJS v1.x compatible](https://img.shields.io/badge/vue%201.x-compatible-green.svg)\n![VueJS v2.x compatible](https://img.shields.io/badge/vue%202.x-compatible-green.svg)\n\nA [socket.io](https://socket.io) plugin for Vue.js.\n\n\u003e **This package does not support native websockets**. At the time, we recommend using [vue-native-websocket](https://github.com/nathantsoi/vue-native-websocket) or [implementing it yourself](https://alligator.io/vuejs/vue-socketio/). For ongoing discussion on this, please visit [#2](https://github.com/icebob/vue-websocket/issues/2).\n\n## Installation\nYou can either install this package with `npm`, or manually by downloading the primary plugin file.\n\n### npm\n\n```bash\n$ npm install -S vue-websocket\n```\n\n### Manual\nDownload the production [`vue-websocket.js`](https://raw.githubusercontent.com/icebob/vue-websocket/master/dist/vue-websocket.js) file. This link is a mirror of the same file found in the `dist` directory of this project.\n\n## Usage\nRegister the plugin. By default, it will connect to `/`:\n\n```js\nimport VueWebsocket from \"vue-websocket\";\nVue.use(VueWebsocket);\n```\n\nOr to connect to another address:\n\n```js\nVue.use(VueWebsocket, \"ws://otherserver:8080\");\n```\n\nYou can also pass options:\n\n```js\nVue.use(VueWebsocket, \"ws://otherserver:8080\", {\n\treconnection: false\n});\n```\n\nTo use it in your components:\n\n```html\n\u003cscript\u003e\n\texport default {\n\n\t\tmethods: {\n\t\t\tadd() {\n\t\t  \t\t// Emit the server side\n\t\t  \t\tthis.$socket.emit(\"add\", { a: 5, b: 3 });\n\t\t\t},\n\n\t\t\tget() {\n\t\t  \t\tthis.$socket.emit(\"get\", { id: 12 }, (response) =\u003e {\n\t\t\t\t\t...\n\t\t\t\t});\n\t\t\t}\n\t\t},\n\n\t\tsocket: {\n\t\t\t// Prefix for event names\n\t\t\t// prefix: \"/counter/\",\n\n\t\t\t// If you set `namespace`, it will create a new socket connection to the namespace instead of `/`\n\t\t\t// namespace: \"/counter\",\n\n\t\t\tevents: {\n\n\t\t\t\t// Similar as this.$socket.on(\"changed\", (msg) =\u003e { ... });\n\t\t\t\t// If you set `prefix` to `/counter/`, the event name will be `/counter/changed`\n\t\t\t\t//\n\t\t\t\tchanged(msg) {\n\t\t\t\t\tconsole.log(\"Something changed: \" + msg);\n\t\t\t\t}\n\n\t\t\t\t/* common socket.io events\n\t\t\t\tconnect() {\n\t\t\t\t\tconsole.log(\"Websocket connected to \" + this.$socket.nsp);\n\t\t\t\t},\n\n\t\t\t\tdisconnect() {\n\t\t\t\t\tconsole.log(\"Websocket disconnected from \" + this.$socket.nsp);\n\t\t\t\t},\n\n\t\t\t\terror(err) {\n\t\t\t\t\tconsole.error(\"Websocket error!\", err);\n\t\t\t\t}\n\t\t\t\t*/\n\n\t\t\t}\n\t\t}\n\t};\n\n\u003c/script\u003e\n```\n\n## Develop\n\n### Building\nThis command will build a distributable version in the `dist` directory:\n\n```bash\n$ npm run build\n```\n\n## Testing\nThis package uses [`karma`](https://www.npmjs.com/package/karma) for testing. You can run the tests like so:\n\n```bash\n$ npm test\n```\n\n## Contribution\nPlease send pull requests improving the usage and fixing bugs, improving documentation and providing better examples, or providing some testing, because these things are important.\n\n## License\n`vue-websocket` is available under the [MIT license](https://tldrlegal.com/license/mit-license).\n\n## Contact\n\nCopyright © 2018 Icebob\n\n[![@icebob](https://img.shields.io/badge/github-icebob-green.svg)](https://github.com/icebob) [![@icebob](https://img.shields.io/badge/twitter-Icebobcsi-blue.svg)](https://twitter.com/Icebobcsi)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficebob%2Fvue-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficebob%2Fvue-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficebob%2Fvue-websocket/lists"}