Vue JS Event bus data not working outside scope of event

Viewed 118

I am using event bus to show alert on update data.so whenever user update the data i want to show an alert showing "Data is udpated" so for that i am using event bus

here is BlogEdit.vue Component where i am firing event

app.$router.push('/', () => {
    vueBus.$emit('showAlertBox')
})

And In BlogList.vue I am listning for this event

data: function(){
    return {
        showalert: false,
    }
},
vueBus.$on('showAlertBox',(data) => {
    this.showalert = true;
    console.log(this.showalert); //Returns True
})
console.log(this.showalert); //Returns False

But the result is unexpected as it change back to false.

Why this.showalert changed to false ? So that cause to not showing alert box.

Since i am new to vue js i read the documenatation and other solutions but i cant figure out where am i going wrong with this.

0 Answers
Related