0

Here my code :

A random component :

watch: {
          'notifications' : {
            handler(newVal) {
              let questionnaireTypes = ['TwoDaysConnected', 'OneWeekConnected', 'TwoWeekInactive']
              if(newVal) {
                this.checkDisplayQuestionnaire(questionnaireTypes)
              }
            },
            immediate: false
          }
        },

The method in mixin_common.js :

    import EventBus from "./event-bus.js"

export default window.mixin_common = {
    methods: {
        checkDisplayQuestionnaire(questionnaireTypes) {
          let stateNotifications = this.$store.state.notifications
          EventBus.$emit('openQuestionnaireExperimentationModalWithDatas', 
          stateNotifications)
        }
    }

The component where is the modal i want to open with the EventBus :

import EventBus from "./event-bus.js"

     methods: {
        openModal() {
          this.$bvModal.show('questionnaireExperimentationModal')
        },
      },
      mounted() {
        EventBus.$on('openQuestionnaireExperimentationModalWithDatas', (notifications) => {
          this.notifications = notifications
          this.openModal()
        })

Event-bus.js :

import Vue from 'vue'

const EventBus = new Vue();

export default EventBus;

Actually, the modal does not open, the only way it works is when i place the EventBus.$emit('openQuestionnaireExperimentationModalWithDatas', stateNotifications) directly in the random component, without using the mixin, but i need to open it with the mixin if it's possible.

Anyone have an idea of how to do it?

Tony S
  • 491
  • 6
  • 26

0 Answers0