如何解决vue router路由钩子地址 与 window location href 不符问题

页面跳转前:/
页面跳转后:/login

未使用计时器:在after each中访问 window location href 是 跳转前的/

使用计时器:在after each中访问 window location href 是 跳转后的/login

阅读 8.6k
2 个回答

路由跳转是异步的,用

this.$nextTick(() => {
// 在这里获取 href
})

你用window location href 干啥,路由的信息都在$route

推荐问题