beforeRouteEnter (to, from, next) {
next(vm => {
console.log(vm.data);
});
}
next()回调没有执行?
beforeRouteEnter (to, from, next) {
next(vm => {
console.log(vm.data);
});
}
next()回调没有执行?
VueJS文档:https://router.vuejs.org/en/a...
const Foo = {
template: `...`,
beforeRouteEnter (to, from, next) {
}
}
需要把beforeRouteEnter
写在路由组件定义里,你可能是直接写到全局了所以没用。
请问楼主问题解决了吗?
我也写在了export中了,但是beforeRouteEnter
并没有起作用,to和from不能打印出来,楼主可以吗?
1. beforeRouteEnter(to, from, next) {} 这个玩意儿,只在当前进入的路由页面生效。
如果你的返回按钮是在其他组件,如:<my-header></myheader>中,那么抱歉,你的beforeRouteEnter都执行不到。
2. beforeRouteEnter(to, from, next) {
// 你在此处打印data中的数据,会无情反你错误。
// 官网解释:(beforeRouteEnter 守卫不能访问this,因为守卫在导航确认前被调用,因此即将登场的新组件还没被创建。)
next(vm => {
// 正确方式
console.log(vm.data);
});
}
9 回答1.6k 阅读✓ 已解决
6 回答1.4k 阅读
3 回答1.4k 阅读✓ 已解决
4 回答1.2k 阅读✓ 已解决
2 回答1.1k 阅读✓ 已解决
3 回答976 阅读
3 回答1.3k 阅读✓ 已解决
从你给出的代码看不出什么问题。这个函数你是写在哪的?
next
之外to
,from
能正确打印吗?官方的示例,你看看,对比一下自已写的是哪里出问题了:
https://github.com/vuejs/vue-...