0

这个描述起来很混乱,所以我就放一个视频

https://dl.dropboxusercontent.com/s/ju485susn7ypsgx/2015-12-09_15-03-50.mp4?dl=0

当我关闭服务器时, m.request 抛出错误(显然)net::ERR_CONNECTION_REFUSED

  1. 如何处理这些错误并将数据转换为空数组[](我知道.then接受成功和失败回调,但它似乎不起作用)
  2. 为什么我重新打开服务器后应用程序无法开始工作?(似乎问题是m.route停止工作?)
4

1 回答 1

1

我通过编辑 mithril.js 源解决了这个问题。我不得不将调用包装在一个块m.endComputation的底部。finally

我不明白为什么try/catch不起作用,以及为什么finally需要这样做。但我想我会把它作为一个错误发布。

    xhrOptions.onload = xhrOptions.onerror = function(e) {
        try {
            e = e || event;
            var unwrap = (e.type === "load" ? xhrOptions.unwrapSuccess : xhrOptions.unwrapError) || identity;
            var response = unwrap(deserialize(extract(e.target, xhrOptions)), e.target);
            if (e.type === "load") {
                if (type.call(response) === ARRAY && xhrOptions.type) {
                    for (var i = 0; i < response.length; i++) response[i] = new xhrOptions.type(response[i])
                }
                else if (xhrOptions.type) response = new xhrOptions.type(response)
            }
            deferred[e.type === "load" ? "resolve" : "reject"](response)
        }
        catch (e) {
            m.deferred.onerror(e);
            deferred.reject(e)
        } finally {
// This is now in a finally block
            if (xhrOptions.background !== true) m.endComputation()
        }
    };
于 2015-12-10T04:37:01.200 回答