mirror of
https://github.com/MetinSeylan/Vue-Socket.io.git
synced 2025-04-16 15:21:28 +02:00
Update README.md
Added namespaced Vuex modules support example
This commit is contained in:
parent
57887ea0a1
commit
e79876cbd2
1 changed files with 33 additions and 0 deletions
33
README.md
33
README.md
|
@ -107,6 +107,39 @@ export default new Vuex.Store({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
In case of namespaced Vuex module, your code should look like this :
|
||||||
|
|
||||||
|
*File : module.js*
|
||||||
|
``` js
|
||||||
|
import Vue from 'vue'
|
||||||
|
import Vuex from 'vuex'
|
||||||
|
|
||||||
|
Vue.use(Vuex);
|
||||||
|
|
||||||
|
export default new Vuex.Store({
|
||||||
|
namespaced: true,
|
||||||
|
state: {
|
||||||
|
action: 0,
|
||||||
|
message: null
|
||||||
|
},
|
||||||
|
mutations:{
|
||||||
|
SOCKET_MESSAGE: (state, message) => {
|
||||||
|
state.message = message;
|
||||||
|
// This code will fire if an event named 'module/message' is received
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
otherAction: (context, type) => {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
socket_actionListener: (state) => {
|
||||||
|
console.log('Received module/actionListener event !!!');
|
||||||
|
state.action ++;
|
||||||
|
// This code will fire if an event named 'module/actionListener' is received
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
[Realtime Car Tracker System](http://metinseylan.com/)
|
[Realtime Car Tracker System](http://metinseylan.com/)
|
||||||
|
|
Loading…
Add table
Reference in a new issue