0.0.5 • Published 5 years ago

pusher-plugin v0.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

##Vue Pusher Plugin

Simple plugin for managing channels and events within vue utilising pusher-js

##Usage

Import as plugin in your main.js file

//main.js
import Vue from 'vue'
import Pusher from 'pusher-plugin'

Vue.use(Pusher, {
    pusherKey: "yourPublicPusherKey", 
    forceTLS: true, 
    cluster: "eu"
})

Use available methods in components

  • subscribeToPusherChannel(channel)
  • unsubscribeFromPusherChannel(channel)
  • bindEventToPusherChannel(channel, event, callback)
  • unbindEventFromPusherChannel(channel, event, callback = false)
//Hello.vue
<template>
    {{pusherData}}
</template>
<script>
export default {
    data: () => ({
        pusherData: {}
    }),
    created () {
      const vm = this
      vm.subscribeToPusherChannel('test_channel')
      vm.bindEventToPusherChannel('test_event', (data) => {
        vm.pusherData = data
      })
    },
    destroyed () {
      const vm = this
      vm.unbindEventFromPusherChannel('test_event')
      vm.unsubscribeFromPusherChannel('test_channel')
    }
}
</script>