2

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.

TP BIZ
  • 21
  • 4
  • Since there's no whole code I would limitly understand but, Event listener better to be located in `onMounted` method. (if vue2, `mount`) – Ian Cho Mar 25 '21 at 08:03
  • also tried by doing that. Let me know if any other code is needd to show @lan Chao – TP BIZ Mar 25 '21 at 08:44

0 Answers0