我通过编辑 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()
}
};