From a062b3f46f441e1e9cfc78f1edce20c11a430805 Mon Sep 17 00:00:00 2001 From: Sebastien Hernoux Date: Wed, 10 Mar 2021 20:28:39 +0100 Subject: [PATCH] Fix: warning for beforeUnmount hook for vue 3 --- src/index.js | 5 +++-- src/mixin.js | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) 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