js\song.js getLyric()方法中, reject('no lyric') 报错了
来源:7-20 播放器歌词数据解析
diguojin
2017-10-26
./src/common/js/song.js ####这个文件
getLyric() {
if (this.lyric) {
return Promise.resolve(this.lyric)
}
return new Promise((resolve, reject) => {
getLyric(this.mid).then((res) => {
if (res.retcode === ERR_OK) {
this.lyric = Base64.decode(res.lyric)
resolve(this.lyric)
} else {
reject('no lyric')
}
})
})
}ERROR Failed to compile with 1 errors 16:44:
error in ./src/common/js/song.js
✘ http://eslint.org/docs/rules/prefer-promise-reject-errors Expected the Promise rejection reason to be an Error
src\common\js\song.js:28:11
reject('no lyric')
^
我的.eslintrc.js
// https://eslint.org/docs/user-guide/configuring
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
sourceType: 'module'
},
env: {
browser: true,
},
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
extends: 'standard',
// required to lint *.vue files
plugins: [
'html'
],
// add your custom rules here
'rules': {
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
'eol-last': 0,
'space-before-function-paren': 0
}
}然后尝试进行了如下修改
reject('no lyric')
=》
reject(new Error('no lyric'))疑问: 编译就通过了。 不知道是什么原因,是ESlint 一定要求reject 中的参数是一个Error对象吗?
疑问2: 老师的代码直接下载下来编辑就不会报错。。。。。
写回答
3回答
-
bek
2017-12-14
谢了,老兄
00 -
bek
2017-12-14
我的也是这种情况eslint报了这个错误
00 -
ustbhuangyi
2017-10-27
看上去没错啊
00
相似问题