我们注意到启动 Aurelia 应用程序时 IE11 中的行为非常奇怪。 仅当您第一次在新窗口/选项卡中启动应用程序并且鼠标光标不在 IE 窗口区域中时才会发生这种情况(例如,程序是从具有给定 url 的命令行运行的 - 这对我们来说很重要)。然后应用程序停留在具有静态内容的index.html上,但什么也没有发生。 直到您将光标移到窗口上...然后应用程序会神奇地继续运行,没有任何错误和任何问题。
据我调试,当脚本进入 System.import('core-js') promise 时会出现问题。无论是否使用 bluebird Promise,都会发生这种情况。
这是“index.html”的正文。
<script src="jspm_packages/system.js"></script>
<script src="config.js"></script>
<script>
System.import('core-js').then(function () {
return System.import('webcomponents.js/MutationObserver');
}).then(function () {
return System.import('aurelia-bootstrapper');
});
</script>
编辑:
我注意到有帮助的是 promise 超时(至少 1000 毫秒)。您知道是否存在更好的解决方案?
<script src="jspm_packages/npm/bluebird@3.3.3/js/browser/bluebird.js"></script>
<script src="jspm_packages/system.js"></script>
<script src="config.js"></script>
<script>
// IE11 hack for mutation observer/promises error
var promise = new Promise(function (resolve) {
window.setTimeout(
function () {
resolve();
}, 1000);
});
System.import('core-js').then(function() {
return System.import('webcomponents.js/MutationObserver');
}).then(function() {
return System.import('aurelia-bootstrapper');
});
</script>
最佳答案
这是针对由 IE11 突变观察者行为与调度引起的错误的解决方法。此解决方法适用于 bluebird,但不适用于其他 polyfill:
// use timers for scheduling
Promise.setScheduler(function(fn) { setTimeout(fn); });
关于javascript - IE11 promise 奇怪的行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35651193/