异常处理
分类 | Composition API(Vue3) | Options API(Vue3) | Options API(Vue2) |
---|---|---|---|
类型检查 | TypeScript | - | 类型校验 |
错误捕获 | onErrorCaptured() v3.0 | errorCaptured() v3.0 | errorCaptured() v2.5 |
全局设置 | app.config.errorHandler v3.0 | - | Vue.config.errorHandler v2.0 |
- | app.config.warnHandler v3.0 | - | Vue.config.warnHandler v2.4 |
- | app.config. throwUnhandledErrorInProduction v3.5 | - | - |
Vue 日志与警告 | - | - | Vue.config.silent v2.0 |
Vue 生产提示 | - | - | Vue.config.productionTip v2.2 |
大纲
- 异常处理
- 类型检查
- 错误边界
- 全局设置
类型检查
- https://v2.cn.vuejs.org/v2/guide/components-props.html#Prop-验证
- https://v2.cn.vuejs.org/v2/guide/typescript.html#增强类型以配合插件使用
错误边界
全局设置
- app.config.errorHandler
- Vue.config.errorHandler
- app.config.warnHandler
- Vue.config.warnHandler
- app.config.throwUnhandledErrorInProduction
- Vue.config.silent
- Vue.config.productionTip