0

我正在尝试切换到 vuejs3 和新的 vue-router。

现在我看到 beforeRouteEnter 没有暴露:

 // same as beforeRouteUpdate option with no access to `this`
        onBeforeRouteUpdate((to, from, next) => {
            // your logic
            console.log("Hello world") //this is only triggered if the id changes
            next()
        })

所以我的问题是:如何像/dashboard以前一样在特定路线上触发初始 axios 请求?

4

1 回答 1

0

因为在导航的时候已经被确认了setup,所以在路径进入之前是不可能执行代码的。setup

另一个选项#1

您仍然可以使用 options api,因此您仍然可以使用beforeRouteEnter

setup() {
  ...
},
beforeRouteEnter(to, from, next) {
  console.log(to);
}

另一个选项#2

beforeEnter在路由器中使用:

{
  path: '/foo',
  component: Foo,
  beforeEnter(to) {
    console.log(to)
  }
}
于 2021-02-16T12:56:15.460 回答