[![npm](https://img.shields.io/npm/v/nuxt-socket-io.svg)](https://www.npmjs.com/package/nuxt-socket-io)
[![npm](https://img.shields.io/npm/dt/nuxt-socket-io.svg)](https://www.npmjs.com/package/nuxt-socket-io)
[![](https://gitlab.com/richardeschloss/nuxt-socket-io/badges/master/pipeline.svg)](https://gitlab.com/richardeschloss/nuxt-socket-io)
[![](https://gitlab.com/richardeschloss/nuxt-socket-io/badges/master/coverage.svg)](https://gitlab.com/richardeschloss/nuxt-socket-io)
[![NPM](https://img.shields.io/npm/l/nuxt-socket-io.svg)](https://github.com/richardeschloss/nuxt-socket-io/blob/development/LICENSE)
[���� **Release Notes**](./CHANGELOG.md)
# nuxt-socket-io
[Socket.io](https://socket.io/) client and server module for Nuxt
## Features
- Configuration of multiple IO sockets
- Configuration of per-socket namespaces
- Automatic IO Server Registration
- Socket IO Status
- Automatic Error Handling
- Debug logging, enabled with localStorage item 'debug' set to 'nuxt-socket-io'
- Automatic Teardown, enabled by default
- $nuxtSocket vuex module and socket persistence in vuex
- Support for dynamic APIs using the KISS API format
- Support for the IO config in the new Nuxt runtime config (for Nuxt versions >= 2.13)
- Automatic middleware registration
# Important update
* v1.1.14+ uses socket.io 3.x. You may find the migration [here](https://socket.io/docs/v3/migrating-from-2-x-to-3-0/index.html)
* v1.1.13 uses socket.io 2.x . Clamp the version to 1.1.13 if not ready to update.
# Setup
1. Add `nuxt-socket-io` dependency to your project
```bash
yarn add nuxt-socket-io # or npm install nuxt-socket-io
```
2. Add `nuxt-socket-io` to the `modules` section of `nuxt.config.js`
```js
{
modules: [
'nuxt-socket-io',
],
io: {
// module options
sockets: [{
name: 'main',
url: 'http://localhost:3000'
}]
}
}
```
3. Use it in your components:
```js
{
mounted() {
this.socket = this.$nuxtSocket({
channel: '/index'
})
/* Listen for events: */
this.socket
.on('someEvent', (msg, cb) => {
/* Handle event */
})
},
methods: {
method1() {
/* Emit events */
this.socket.emit('method1', {
hello: 'world'
}, (resp) => {
/* Handle response, if any */
})
}
}
}
```
## Documentation
But WAIT! There's so much more you can do!! Check out the documentation:
> https://nuxt-socket-io.netlify.app/
There you will see:
- More details about the features, configuration and usage
- Demos and examples, and link to a codesandbox so you can try things out as you follow along!
- All the old docs that you originally saw here were *moved* there and better organized. Things should be much easier to follow now!
### Resources
- Follow me and the series on [medium.com](https://medium.com/@richard.e.schloss)
- Socket.io Client docs [here](https://socket.io/docs/client-api/)
- Socket.io Server docs [here](https://socket.io/docs/server-api/)
## Development
1. Clone this repository
2. Install dependencies using `yarn install` or `npm install`
3. Start development server using `yarn dev` or `npm run dev`
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
nuxt-socket-io 客户端和服务器模块 特征 多个IO插座的组态 每个套接字名称空间的配置 IO服务器自动注册 套接字IO状态 自动错误处理 调试日志记录,通过将localStorage项目“ debug”设置为“ nuxt-socket-io”启用 自动拆解,默认情况下启用 $ nuxtSocket vuex模块和vuex中的套接字持久性 使用KISS API格式支持动态API 在新的Nuxt运行时配置中支持IO配置(对于Nuxt版本> = 2.13) 自动中间件注册 重要更新 v1.1.14 +使用socket.io3.x。 您可以在找到迁移 v1.1.13使用socket.io 2.x。 如果尚未准备好更新,请将版本限制为1.1.13。 设置 将nuxt-socket-io依赖项添加到您的项目中 yarn add nuxt-socket-io # or npm ins
资源详情
资源评论
资源推荐
收起资源包目录
nuxt-socket-io-master.zip (87个子文件)
nuxt-socket-io-master
.gitignore 1KB
.babelrc 301B
components
Messages.vue 2KB
ChannelUsers.vue 265B
Samples.vue 2KB
RoomSelect.vue 957B
Toaster.vue 658B
Logo.vue 8KB
Chats.vue 1KB
ChannelSelect.vue 2KB
README.md 205B
ChatInput.vue 595B
ProgressBar.vue 2KB
SocketStatus.vue 2KB
middleware
README.md 383B
package.json 3KB
.nycrc 201B
server
apis.js 454B
index.js 819B
io.js 157B
db.js 661B
io.bad1.js 32B
io
newfile.ts 109B
channel.js 3KB
chat.js 307B
rooms.js 380B
nsp.bad1.js 22B
room.js 2KB
nsp.bad3.js 51B
index.js 1KB
nsp.bad2.js 25B
dynamic.js 2KB
examples.js 2KB
p2p.js 1KB
middlewares.js 499B
io.bad2.js 43B
jsconfig.json 230B
package-lock.json 863KB
types.d.ts 73B
.gitlab-ci.yml 776B
assets
main.css 117B
README.md 296B
CONTRIBUTING.md 3KB
LICENSE 1KB
CHANGELOG.md 8KB
static
README.md 435B
favicon.ico 1KB
nuxt.config.js 4KB
.github
FUNDING.yml 727B
utils
common.js 450B
esm.js 645B
.eslintrc.js 375B
README.md 3KB
.eslintignore 49B
e2e.config.js 462B
layouts
default.vue 963B
README.md 261B
store
index.js 379B
examples.js 547B
README.md 400B
io
types.d.ts 9KB
plugin.js 28KB
module.js 4KB
specs.config.js 544B
pages
ioStatus.vue 938B
index.vue 4KB
ioApi.vue 3KB
rooms
_room.vue 2KB
_room
_channel.vue 2KB
README.md 286B
examples.vue 661B
rooms.vue 902B
test
e2e
IOStatus.spec.js 2KB
Channel.spec.js 2KB
Rooms.spec.js 1KB
Samples.spec.js 2KB
ProgressBar.spec.js 2KB
Messages.spec.js 3KB
Room.spec.js 2KB
utils.js 3KB
e2e.setup.js 793B
specs.setup.js 374B
specs
Module.spec.js 7KB
Plugin.spec.js 40KB
.editorconfig 207B
.prettierrc 70B
yarn.lock 468KB
共 87 条
- 1
Airva128
- 粉丝: 24
- 资源: 4670
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1