[Vuejs]-Vue js multiple instances of module

0👍

I’m pretty sure it’s happening because you’re not properly removing the component from the DOM between different app states (though you think you do).

  1. Check your v-ifs, sometimes you can notice some redundancy on their conditions.

  2. Be sure you’re not allowing Bus instance to register the same even handler twice, thus calling Bus.$off on every destroy hook in the lifecycle.

Example:

export default {
  components: {
    StripeCheckout
  },
  methods: {
    onStripeSuccess (payload) {
      // do stuff with payload
    }
  },
  created () {
    Bus.$on('vue-stripe.success', this.onStripeSuccess)
  },
  beforeDestroy () {
    Bus.$off('vue-stripe.success')
  }
}

More on this:

Component lifecycle: https://v2.vuejs.org/v2/guide/instance.html#Lifecycle-Diagram

Removing event listeners: https://v2.vuejs.org/v2/api/#vm-off

Leave a comment