简体   繁体   English

没有兑现的承诺没有捕获块(未处理的拒绝)

[英]not fulfilled Promises without catch block (unhandledrejection) javascript

I write project in VueJs Javascript and would like to see in the console messages, if any of my Promises are not fulfilled and do not have catch block. 我用VueJs Javascript编写项目,并且希望在控制台消息中查看我的任何Promises是否未实现且没有catch块。

I tried something like this 我尝试过这样的事情

Promise.reject("error!");
window.addEventListener('unhandledrejection', event => {
  console.log('i am error')
});

but without success. 但没有成功。 Are there any other approach? 还有其他方法吗? Or how could I fix this one? 或者我该如何解决这个问题?

unhandledrejection is for the native Promises currently only implemented in Chrome. unhandledrejection适用于当前仅在Chrome中实现的本机Promises。 If you want to log those error also in other browser you would need to overwrite the native Promise with another implementation like bluebird: 如果您还想在其他浏览器中记录这些错误,则需要使用诸如bluebird的另一种实现覆盖本机Promise:

 Promise.reject("error!"); window.addEventListener('unhandledrejection', event => { console.log('i am error') }); 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/bluebird/3.5.1/bluebird.js"></script> 

You need to make sure that bluebird is loaded as the first script. 您需要确保将bluebird作为第一个脚本加载。

bluebird: Error management configuration bluebird:错误管理配置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM