mirror of
https://github.com/tenrok/vue-native-websocket.git
synced 2026-06-23 13:50:35 +03:00
Add connect and disconnect functions
This commit is contained in:
+11
-2
@@ -6,9 +6,18 @@ export default {
|
|||||||
install (Vue, connection, opts = {}) {
|
install (Vue, connection, opts = {}) {
|
||||||
if (!connection) { throw new Error('[vue-native-socket] cannot locate connection') }
|
if (!connection) { throw new Error('[vue-native-socket] cannot locate connection') }
|
||||||
|
|
||||||
let observer = new Observer(connection, opts)
|
let observer = null
|
||||||
|
|
||||||
Vue.prototype.$socket = observer.WebSocket
|
Vue.prototype.$connect = function () {
|
||||||
|
observer = new Observer(connection, opts)
|
||||||
|
Vue.prototype.$socket = observer.WebSocket
|
||||||
|
}
|
||||||
|
|
||||||
|
Vue.prototype.$disconnect = function () {
|
||||||
|
observer.reconnection = false
|
||||||
|
Vue.prototype.$socket.close()
|
||||||
|
delete Vue.prototype.$socket
|
||||||
|
}
|
||||||
|
|
||||||
Vue.mixin({
|
Vue.mixin({
|
||||||
created () {
|
created () {
|
||||||
|
|||||||
Reference in New Issue
Block a user