Arrow function should not return assignment no-return-assign 这是eslint检查报错。
说明,在学习B站的《2019年最全最新Vue、Vuejs教程,从入门到精通》P221时,遇到的问题。因为引用了eslint的检查代码,导致检查报错,代码并没有问题,是eslint检验的问题。
解决方法: 1.去掉eslint
2. 修改代码,符合eslint
原代码
if (this.isSelectAll) {
this.cartList.forEach(item => item.checked = false)
} else {
this.cartList.forEach(item => item.checked = true)
}
更改后的代码
if (this.isSelectAll) {
this.cartList.forEach(item => {
item.checked = false })
} else {
this.cartList.forEach(item => {
item.checked = true })
}
在学习过箭头函数,可以得知加上的{}是可以省略的,但是eslint的规则要求这么必须有。