【问题标题】:onBeforeEnter does not exist in vue-router@nextvue-router@next 中不存在 onBeforeEnter
【发布时间】:2021-05-19 05:19:00
【问题描述】:

我正在尝试切换到 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-requests?

【问题讨论】:

标签: vue.js vue-router vuejs3 vue-router4


【解决方案1】:

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)
  }
}

【讨论】:

    猜你喜欢
    • 2020-07-24
    • 1970-01-01
    • 2019-08-18
    • 1970-01-01
    • 2021-06-11
    • 2018-02-09
    • 2019-09-09
    • 2020-09-16
    • 2019-02-03
    相关资源
    最近更新 更多