在选项式的写法中组件的守卫事件无法被正确调用 #2505
Unanswered
AiFu-o
asked this question in
Help and Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Reproduction
4.*
Steps to reproduce the bug
在选项式的页面中注册页面的子组件中调用守卫事件beforeRouteLeave
但是在声明式的页面中的子组件调用onBeforeRouteLeave就可以
Expected behavior
在注册页面的子组件中调用守卫事件生效
Actual behavior
在注册页面的子组件中调用守卫事件不生效
Additional information
排查源码发现问题在于选项式的守卫事件只是直接调用了 component 的 守卫事件方法 而这种方式无法对组件中的子组件进行扫描
但是在声明式中是把onBeforeRouteLeave直接注册成了事件 是组件主动调用的 而不是 vue-router 自动获取的 目前的解决办法是在 vue 的 created 或 mounted生命周期中调用onBeforeRouteLeave 手动注册事件
希望可以更新文档或使用其他方式扫描选项式的守卫事件
Beta Was this translation helpful? Give feedback.
All reactions