Vue JS 事件总线数据在事件范围之外不起作用

问题描述

我正在使用事件总线来显示更新数据的警报。因此,每当用户更新数据时,我都想显示一个警报,显示“数据已更新”,因此我正在使用事件总线 >

这里是BlogEdit.vue我正在触发事件的组件

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

并且在 BlogList.vue 我正在为这个事件做列表

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

但结果出乎意料,因为它变回了 false。

为什么 this.showalert 变成了 false ?所以导致不显示警告框。

因为我是 vue js 的新手,所以我阅读了文档和其他解决方案,但我不知道我哪里出错了。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)