xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Vue & Error Boundary All In One

Vue & Error Boundary

Vue 错误处理

场景:单个小 UI 组件出错, 导致整个应用无法正常使用

目的:兜底,优雅降级,健壮性

https://cn.vuejs.org/api/

https://www.npmjs.com/package/vue-error-boundary

方法 支持版本 截图
app.config.errorHandler Vue 2.x, Vue 3.x image
errorCaptured Vue 2.x, Vue 3.x image
onErrorCaptured() Vue 3.x image

Vue 3 / Vue errorCaptured

app.config.errorHandler

用于为应用内抛出的未捕获错误指定一个全局处理函数

interface AppConfig {
  errorHandler?: (
    err: unknown,
    instance: ComponentPublicInstance | null,
    // `info` 是一个 Vue 特定的错误信息
    // 例如:错误是在哪个生命周期的钩子上抛出的
    info: string
  ) => void
}

https://cn.vuejs.org/api/application.html#app-config-errorhandler

errorCaptured

在捕获了后代组件传递的错误时调用。

interface ComponentOptions {
  errorCaptured?(
    this: ComponentPublicInstance,
    err: unknown,
    instance: ComponentPublicInstance | null,
    info: string
  ): boolean | void
}

https://cn.vuejs.org/api/options-lifecycle.html#errorcaptured

onErrorCaptured()

注册一个钩子,在捕获了后代组件传递的错误时调用。

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, 禁止转载 🈲️,侵权必究⚠️!


posted @   xgqfrms  阅读(170)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 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
点击右上角即可分享
微信分享提示