Vuejs太灵活了,需要仔细分辨区别
比如vue-router
,可以在多个地方写router hook
,比如可以写全局guard,可以per-route
写guard,甚至可以在component
里写。
那么,在component
里写,似乎不错,但一些hook,比如beforeRouteEnter
,是不能用到这个component本身的,因为:
The beforeRouteEnter guard does NOT have access to this, because the
guard is called before the navigation is confirmed, thus the new
entering component has not even been created yet.