N
N
nastya_zholudeva2018-06-24 22:49:13
Vue.js
nastya_zholudeva, 2018-06-24 22:49:13

Why doesn't the event bus hear the event?

There are 2 independent pages. By clicking on a button on one page

//search.vue
<html><button @click="showSelectedCompanies">ПОСМОТРЕТЬ</button> </html>
<script>
import {bus} from '../../bus'

export default {
showSelectedCompanies () {
      this.items = this.items.filter(e => this.selectedCompaniesId.includes(e.id))
      console.log('this.itemsSearch', this.items)
      bus.$emit('selectedCompanies', this.items)
      this.$router.push({path: 'selected'})
    },
}
<script>

The array this.itemsmust be passed to the second page
//Selected.vue
<script>
import {bus} from '../../bus'

export default {
mounted () {
    bus.$on('selectedCompanies', (data) => {
      console.log('data', data)
      this.items = data
      console.log('this.items', this.items)
    })
  },
  beforeDestroy () {
    bus.$off('selectedCompanies')
  }
}
</script>

The console prints out an array that is prepared to be passed on click, but what should be printed when listening to this event is not.
5b2ff51820842400705293.png
Interestingly, in vue devtools this event with the required array is filled.
5b2ff5472453f684050884.png
What could be wrong?
PS On the Search page I listen to another event and everything is fine

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2018-06-24
@nastya_zholudeva

Apparently the component where you send the event does not exist or the signature in it did not have time to occur.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question