mirror of
https://github.com/MetinSeylan/Vue-Socket.io.git
synced 2025-04-16 15:21:28 +02:00
Update mixin.js
This commit is contained in:
parent
4b7c282d0c
commit
fc7ad95293
1 changed files with 17 additions and 22 deletions
31
src/mixin.js
31
src/mixin.js
|
@ -5,29 +5,24 @@ export default {
|
||||||
*/
|
*/
|
||||||
created(){
|
created(){
|
||||||
|
|
||||||
if(this.$options.sockets){
|
this.sockets = {
|
||||||
|
subscribe: (event, callback) => {
|
||||||
|
this.$vueSocketIo.emitter.addListener(event, callback, this);
|
||||||
|
},
|
||||||
|
unsubscribe: (event) => {
|
||||||
|
this.$vueSocketIo.emitter.removeListener(event, this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Object.keys(this.$options.sockets).forEach(event => {
|
if(this.sockets){
|
||||||
|
|
||||||
|
Object.keys(this.sockets).forEach(event => {
|
||||||
|
|
||||||
if(event !== 'subscribe' && event !== 'unsubscribe') {
|
if(event !== 'subscribe' && event !== 'unsubscribe') {
|
||||||
this.$vueSocketIo.emitter.addListener(event, this.$options.sockets[event], this);
|
this.$vueSocketIo.emitter.addListener(event, this.$options.sockets[event], this);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.sockets = {
|
|
||||||
subscribe: (event, callback) => {
|
|
||||||
|
|
||||||
this.$vueSocketIo.emitter.addListener(event, callback, this);
|
|
||||||
|
|
||||||
},
|
|
||||||
unsubscribe: (event) => {
|
|
||||||
|
|
||||||
this.$vueSocketIo.emitter.removeListener(event, this);
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
@ -37,9 +32,9 @@ export default {
|
||||||
*/
|
*/
|
||||||
beforeDestroy(){
|
beforeDestroy(){
|
||||||
|
|
||||||
if(this.$options.sockets){
|
if(this.sockets){
|
||||||
|
|
||||||
Object.keys(this.$options.sockets).forEach(event => {
|
Object.keys(this.sockets).forEach(event => {
|
||||||
|
|
||||||
this.$vueSocketIo.emitter.removeListener(event, this);
|
this.$vueSocketIo.emitter.removeListener(event, this);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue