【发布时间】:2020-01-13 18:55:14
【问题描述】:
在大多数情况下,当我使用 this.$router.push() 时,一切正常。但是,在一种情况下,我这样做会引发异常。页面更改得很好 - 只是消息 vue-router.esm.js?8c4f:2007 Uncaught (in promise) 出现在控制台中。
我认为这条特定路线的称呼与其他路线没有任何不同。
下面的代码是路由器失败的地方。 this$1.pending1 和 route 都是对象。我在那里放了一个断点并检查了以下内容:JSON.stringify(this$1.pending) === JSON.stringify(route) 并且返回 true,因此它们具有相同的数据。
在javascript中,除非对象相同,否则对象不被视为相等,但我不知道为什么,在这种情况下,对象是克隆而不是相同。
runQueue(queue, iterator, function () {
var postEnterCbs = [];
var isValid = function () { return this$1.current === route; };
// wait until async components are resolved before
// extracting in-component enter guards
var enterGuards = extractEnterGuards(activated, postEnterCbs, isValid);
var queue = enterGuards.concat(this$1.router.resolveHooks);
runQueue(queue, iterator, function () {
if (this$1.pending !== route) { // EXCEPTION ON THIS LINE
return abort()
}
this$1.pending = null;
onComplete(route);
if (this$1.router.app) {
this$1.router.app.$nextTick(function () {
postEnterCbs.forEach(function (cb) {
cb();
});
});
}
});
});
【问题讨论】:
标签: javascript vue.js vue-router