mirror of
https://github.com/tenrok/vue-native-websocket.git
synced 2026-06-24 13:00:35 +03:00
readme updates
This commit is contained in:
@@ -35,18 +35,12 @@ Vue.use(VueNativeSock, 'ws://localhost:9090', store, {format: 'json'})
|
|||||||
#### On Vuejs instance usage
|
#### On Vuejs instance usage
|
||||||
``` js
|
``` js
|
||||||
var vm = new Vue({
|
var vm = new Vue({
|
||||||
sockets:{
|
|
||||||
connect: function(){
|
|
||||||
console.log('socket connected')
|
|
||||||
},
|
|
||||||
customEmit: function(val){
|
|
||||||
console.log('this method was fired by the socket server. eg: io.emit("customEmit", data)')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
clickButton: function(val){
|
clickButton: function(val) {
|
||||||
// $socket is socket.io-client instance
|
// $socket is [WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) instance
|
||||||
this.$socket.emit('emit_method', val);
|
this.$socket.send('some data')
|
||||||
|
// or with {format: 'json'} enabled
|
||||||
|
this.$socket.sendObj({awesome: 'data'})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -55,13 +49,11 @@ var vm = new Vue({
|
|||||||
#### Dynamic socket event listeners
|
#### Dynamic socket event listeners
|
||||||
Create a new listener
|
Create a new listener
|
||||||
``` js
|
``` js
|
||||||
this.$options.sockets.event_name = (data) => {
|
this.$options.sockets.event_name = (data) => console.log(data)
|
||||||
console.log(data)
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
Remove existing listener
|
Remove existing listener
|
||||||
``` js
|
``` js
|
||||||
delete this.$options.sockets.event_name;
|
delete this.$options.sockets.event_name
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Vuex Store integration
|
#### Vuex Store integration
|
||||||
|
|||||||
Reference in New Issue
Block a user