【问题标题】:In Vue router, why would this happen? this$1.pending !== route在Vue路由器中,为什么会发生这种情况? this$1.pending !== 路线
【发布时间】: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


    【解决方案1】:

    这并不完全是一个答案,但这里是其他遇到相同问题的人的讨论:https://github.com/vuejs/vue-router/issues/2932

    听起来好像没有解决办法,但由于它看起来是无害的,(除了控制台中的消息),我暂时不用担心。

    【讨论】:

      猜你喜欢
      • 2013-08-02
      • 2018-12-19
      • 2021-01-24
      • 1970-01-01
      • 2012-03-22
      • 2013-06-09
      • 2021-04-30
      • 2010-09-22
      相关资源
      最近更新 更多