jaggy / vue-pusher

A small pusher plugin for vue.js
44 stars 15 forks source link

subscribe() and unsubscribe() is undefined when using this.$pusher in Nuxt.js #8

Open fahmiegerton opened 3 years ago

fahmiegerton commented 3 years ago

This function, subscribe() and unsubscribe() is undefined when using this.$pusher in Nuxt.js. I already set the mode to client, follow the instruction, but nothing work. Here's the plugin vue-pusher.js fiile I made.

import Vue from "vue";
// import VuePusher from "vue-pusher";

export default ({$config: {pusherKey, pusherCluster}}) => {
   Vue.use(VuePusher, {api_key: pusherKey, options: {cluster: pusherCluster, encrypted: false}})
}

And using it in the pages like this:

export default {
    ......
    mounted() {
        this.pusher()
    },
   methods: {
        pusher() {
            var channel = this.$pusher.subscribe('railway')
            channel.bind('01', (data) => {
                    // do with the data
            })
        },
      .......
   },
  .....
}

Any idea what is wrong with this conifiguration? thank you