用 beforeUpdate 还是 watch $route,这两种方式是不是等价的?
用 beforeUpdate 还是 watch $route,这两种方式是不是等价的?
|
ss098Apr 26, 2019
1
watch $route 才是用来监听变化的吧,beforeUpdate 其他情况也会触发。
|
|
ss098Apr 26, 2019
2
watch $route 才是用来监听变化的吧,beforeUpdate 其他情况也会触发。
|
|
3
@ss098 哪些情况?
|
|
ss098Apr 26, 2019
4
|
|
EverymanApr 26, 2019
5
应该使用 Vue Router 的导航守卫吧。
https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards 例如,在 Electron 中不能直接看到 chrome 的当前 URL,所以我就用 Vue Router 的 `router.afterEach` 每次路由变化后在 console 打印当前路由信息,以验证路由没错误。 |
|
6
|