如何将Vue的config.errorHandler与Sentry结合使用 Vue公司 </跨度> ?
我想在应用程序中捕获除Sentry之外的错误,但是一旦我实现了config.errorHandler,我就覆盖了Sentry实现。
main.js:
从@“sentry / browser”导入*作为Sentry;
Sentry.init({ dsn:“我的dsn”, 集成:[new Sentry.Integrations.Vue({ Vue公司 </跨度> })]});
//这可以防止使用哨兵Vue.config.errorHandler =(msg,vm,info)=&gt; { 警报(信息)}
当Sentry覆盖时 Vue.config.errorHandler ,它保存了先前声明的引用 errorHandler 并在Sentry处理错误后调用它。 资源
Vue.config.errorHandler
errorHandler
在这种情况下,声明自定义 errorHandler 应该在此之前完成 Vue 构造函数已传递给 new Sentry.Integrations.Vue({ Vue }) 。
Vue
new Sentry.Integrations.Vue({ Vue })
对于上面的代码示例,只需切换自定义顺序 errorHandler 和 Sentry.init() 应该解决这个问题。
Sentry.init()
import * as Sentry from "@sentry/browser"; Vue.config.errorHandler = (msg, vm , info) => { alert(info) } Sentry.init({ dsn: "my dsn", integrations: [new Sentry.Integrations.Vue({ Vue })] });