diff --git a/src/index.js b/src/index.js index c1971f7..21dcdc5 100644 --- a/src/index.js +++ b/src/index.js @@ -28,17 +28,18 @@ export default class VueSocketIO { */ install(Vue){ - const version = Number(Vue.version.split('.')[0]) + const version = Number(Vue.version.split('.')[0]); if (version >= 3) { Vue.config.globalProperties.$socket = this.io; Vue.config.globalProperties.$vueSocketIo = this; + Vue.mixin(Mixin(true)); } else { Vue.prototype.$socket = this.io; Vue.prototype.$vueSocketIo = this; + Vue.mixin(Mixin(false)); } - Vue.mixin(Mixin); Logger.info('Vue-Socket.io plugin enabled'); diff --git a/src/mixin.js b/src/mixin.js index a727dfd..2e920c5 100644 --- a/src/mixin.js +++ b/src/mixin.js @@ -1,4 +1,4 @@ -export default { +export default (isVue3) => ({ /** * Assign runtime callbacks @@ -39,7 +39,7 @@ export default { /** * unsubscribe when component unmounting */ - beforeDestroy(){ + [isVue3 ? 'beforeUnmount' : 'beforeDestroy'](){ if(this.$options.sockets){ @@ -53,4 +53,4 @@ export default { } -} \ No newline at end of file +}); \ No newline at end of file