Vue & Error Boundary All In One
Vue & Error Boundary
Vue 错误处理
场景:单个小 UI 组件出错, 导致整个应用无法正常使用
目的:兜底,优雅降级,健壮性
https://www.npmjs.com/package/vue-error-boundary
方法 | 支持版本 | 截图 |
---|---|---|
app.config.errorHandler |
Vue 2.x, Vue 3.x | ![]() |
errorCaptured |
Vue 2.x, Vue 3.x | ![]() |
onErrorCaptured() |
Vue 3.x | ![]() |
Vue 3 / Vue errorCaptured
用于为应用内抛出的未捕获错误指定一个全局处理函数
。
interface AppConfig {
errorHandler?: (
err: unknown,
instance: ComponentPublicInstance | null,
// `info` 是一个 Vue 特定的错误信息
// 例如:错误是在哪个生命周期的钩子上抛出的
info: string
) => void
}
https://cn.vuejs.org/api/application.html#app-config-errorhandler
在捕获了后代组件传递的错误时调用。
interface ComponentOptions {
errorCaptured?(
this: ComponentPublicInstance,
err: unknown,
instance: ComponentPublicInstance | null,
info: string
): boolean | void
}
https://cn.vuejs.org/api/options-lifecycle.html#errorcaptured
注册一个钩子,在捕获了后代组件传递的错误时调用。
function onErrorCaptured(callback: ErrorCapturedHook): void
type ErrorCapturedHook = (
err: unknown,
instance: ComponentPublicInstance | null,
info: string
) => boolean | void
https://cn.vuejs.org/api/composition-api-lifecycle.html#onerrorcaptured
refs
©xgqfrms 2012-2021
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/17146584.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2022-02-23 echarts & v-charts error All in One
2022-02-23 js cut string by bytes All In One
2022-02-23 TypeScript Object vs object vs {} All In One
2022-02-23 react call child component method from parent & typescript All In One
2022-02-23 Windows 10 & VSCode terminal show current git branch All In One
2021-02-23 How to show emoji keyboard on macOS All In One
2021-02-23 vanilla js overload function & override function All In One