我有一个用例,我需要自己实例化组件并手动安装它们。我想捕获实例化和安装错误,但是我找不到方法。我已经尝试了所有我能想到的所有功能Vue.config.errorHandler
,... vm.errrorHandler
,vm.errorCatcher
(在父级上)...,但没有丝毫保留。
我想知道为什么这不起作用?
try {
const vm = new MyCustomComponent(); // this is having an error (no template for instance)
vm.$mount();
} catch (e) {
console.log(e); // this is never called
}
// manualy attaching the mounted component to the DOM myself afterward.
参考文档链接:https : //vuejs.org/v2/api/#vm-mount
编辑:添加了一个小提琴:https://jsfiddle.net/2pzmn3ue/
如果查看Vue源代码,您会注意到这是一个警告-并非错误。因此,您应该使用Vue.config.warnHandler
而不是errorHandler
。您的处理程序将使用3个参数-警告消息,组件实例和组件跟踪(不是stacktrace)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句