Skip to content
This repository was archived by the owner on Oct 2, 2020. It is now read-only.

Commit 98994e0

Browse files
authored
Update README.md
1 parent caf1523 commit 98994e0

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ https://github.com/icebob/vue-websocket/archive/master.zip
1515
```
1616

1717
## Usage
18-
Register the plugin
18+
Register the plugin, it will connect to `/`
1919
```js
2020
import VueWebsocket from "vue-websocket";
2121
Vue.use(VueWebsocket);
@@ -38,22 +38,35 @@ Use it in your components:
3838
export default {
3939
4040
methods: {
41-
// Emit the server side
42-
this.$socket.emit("add", { a: 5 });
41+
add() {
42+
// Emit the server side
43+
this.$socket.emit("add", { a: 5, b: 3 });
44+
},
45+
46+
get() {
47+
this.$socket.emit("get", { id: 12 }, (response) => {
48+
...
49+
});
50+
}
4351
},
4452
4553
socket: {
54+
// Prefix for event names
4655
// prefix: "/counter/",
56+
57+
// If you set `namespace`, it will create a new socket connection to the namespace instead of `/`
4758
// namespace: "/counter",
4859
4960
events: {
5061
5162
// Similar as this.$socket.on("changed", (msg) => { ... });
63+
// If you set `prefix` to `/counter/`, the event name will be `/counter/changed`
64+
//
5265
changed(msg) {
5366
console.log("Something changed: " + msg);
5467
}
5568
56-
/*
69+
/* common socket.io events
5770
connect() {
5871
console.log("Websocket connected to " + this.$socket.nsp);
5972
},

0 commit comments

Comments
 (0)