我正在尝试切换到vuejs3和新的vue-router。
现在我看到在forerouteenter未暴露之前:
// 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请求?
在航线进入setup
之前不可能执行代码,因为在setup
时航行已经确定。
另一个选项#1
您仍然可以使用选项api,因此您仍然可以使用beforeRouteEnter
:
setup() {
...
},
beforeRouteEnter(to, from, next) {
console.log(to);
}
另一个选项#2
在路由器中使用beforeEnter
:
{
path: '/foo',
component: Foo,
beforeEnter(to) {
console.log(to)
}
}