vue.js - Vue Cli 混淆的 ESLint 错误
问题描述
我正在将 Vue Cli 用于一个项目,该项目包含.eslintrc.js
一个我试图坚持的项目。它在下面的代码中发现了一个错误。
getTags (url) {
axios.get('http://example.test/api' + url).then(response => {
this.tags = response.data.data
}).catch(error => {
this.tags = []
})
}
确切的错误是代码的这部分(在 之后.catch
)
(error => {
this.tags = []
this.loadingTags = false
})
错误是[eslint] Expected error to be handled. (handle-callback-err)
但我很困惑,因为不是.catch(error =>
捕捉错误吗?我看不到问题
解决方案
error
您必须在错误回调中对参数做一些事情。正如规则所说:
在 Node.js 中,处理异步行为的常见模式称为回调模式。此模式需要一个 Error 对象或 null 作为回调的第一个参数。忘记处理这些错误可能会导致您的应用程序出现一些非常奇怪的行为。
因此,您可以记录它或在您创建的处理程序中处理它:
(error => {
console.log(error)
// or
this.handleError(error)
this.tags = []
this.loadingTags = false
})
推荐阅读
- angular - 替换角度输入中的插值
- java - Eclipse Mockito 调试;不会在间谍 bean 的断点处停止
- wso2 - WSO2 EI/ESB:使用正则表达式实现 Switch mediator 和 Filter mediator
- visual-studio - Blazor 的 Resharper 问题
- python - Python Selenium 去网页中的一个字段并输入新值
- android - 如何在 Widget 中以编程方式设置 android:backgroundTint
- java - 尝试使用 cucumber 和 jenkins 重新运行失败的测试时没有填充 Rerun.txt
- python-3.x - 如何将 itertool 产品用于数组
- regex - 正则表达式删除两个字符串之间的所有字符串?
- python - django-filter SQLite3 DateRanges 与 Startdate 和 Enddate