【小问题记录】兄弟组件跳转,数据局部刷新

问题:A页面与B页面是兄弟页面时,B页面跳转到A页面后要求A页面的表格数据局部刷新

解决办法:

  1. 在A页面created钩子里添加window监听事件,addEventListener(事件名,处理函数)
 created() {
window.addEventListener('updateList', this.getList);
}

2.在B页面跳转时 添加dispatchEvent

this.$router.push("/A页面路径")
window.dispatchEvent(new CustomEvent('updateList'))

3.在A页面destoryed钩子里销毁这个监听事件,否则页面会报404

 destroyed() {
    window.removeEventListener('updateList');
  }

你可能感兴趣的:(前端,vue.js)