beforeRouteLeave does not take effect in subcomponents

There are parent-child components in the page. When you need to leave the current page, you need to trigger an event in a child component or modify a value in a child component.

Two ways have been tried here:

1. Add routing guard

In the .vue file of the child component, the beforeRouteLeave hook is used, but it is not triggered. The test found that the beforeRouteLeave added in the parent component can be triggered.

2. Use the beforeDestory hook (triggered when the component is destroyed)

The subcomponent uses the beforeDestroy hook, and when leaving the page, the subcomponent's beforeDestroy life hook can be triggered.

Guess you like

Origin blog.csdn.net/weixin_50114203/article/details/129857580