This commit is contained in:
Sébastien H 2022-01-12 12:32:02 -05:00 committed by GitHub
commit 7e5fb96c80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 9 deletions

View file

@ -57,6 +57,7 @@ new Vue({
``` ```
##### Using socket.io-client Instance ##### Using socket.io-client Instance
###### For vue 2
``` javascript ``` javascript
import Vue from 'vue' import Vue from 'vue'
import store from './store' import store from './store'
@ -84,6 +85,31 @@ new Vue({
}).$mount('#app') }).$mount('#app')
``` ```
###### For vue 3
``` javascript
import Vue from 'vue'
import store from './store'
import App from './App.vue'
import VueSocketIO from 'vue-socket.io'
import SocketIO from 'socket.io-client'
const vueSocket = new VueSocketIO({
debug: true,
connection: SocketIO('http://metinseylan.com:1992', options), //options object is Optional
vuex: {
store,
actionPrefix: "SOCKET_",
mutationPrefix: "SOCKET_"
}
});
createApp(App)
.use(store)
.use(router)
.use(vueSocket)
.mount('#app');
```
**Parameters**|**Type's**|**Default**|**Required**|**Description** **Parameters**|**Type's**|**Default**|**Required**|**Description**
-----|-----|-----|-----|----- -----|-----|-----|-----|-----
debug|Boolean|`false`|Optional|Enable logging for debug debug|Boolean|`false`|Optional|Enable logging for debug

File diff suppressed because one or more lines are too long

View file

@ -28,17 +28,18 @@ export default class VueSocketIO {
*/ */
install(Vue){ install(Vue){
const version = Number(Vue.version.split('.')[0]) const version = Number(Vue.version.split('.')[0]);
if (version >= 3) { if (version >= 3) {
Vue.config.globalProperties.$socket = this.io; Vue.config.globalProperties.$socket = this.io;
Vue.config.globalProperties.$vueSocketIo = this; Vue.config.globalProperties.$vueSocketIo = this;
Vue.mixin(Mixin(true));
} else { } else {
Vue.prototype.$socket = this.io; Vue.prototype.$socket = this.io;
Vue.prototype.$vueSocketIo = this; Vue.prototype.$vueSocketIo = this;
Vue.mixin(Mixin(false));
} }
Vue.mixin(Mixin);
Logger.info('Vue-Socket.io plugin enabled'); Logger.info('Vue-Socket.io plugin enabled');

View file

@ -1,4 +1,4 @@
export default { export default (isVue3) => ({
/** /**
* Assign runtime callbacks * Assign runtime callbacks
@ -39,7 +39,7 @@ export default {
/** /**
* unsubscribe when component unmounting * unsubscribe when component unmounting
*/ */
beforeDestroy(){ [isVue3 ? 'beforeUnmount' : 'beforeDestroy'](){
if(this.$options.sockets){ if(this.$options.sockets){
@ -53,4 +53,4 @@ export default {
} }
} });