各种问题解决方案积累
程序员文章站
2022-04-15 17:35:55
...
1、Unexpected lexical declaration in case block
正如字面意思一样:case块中意外的词法声明,是一个eslint(no-case-declarations)的报错
例如:下面代码就会报错
switch (name) {
case 'zhangsan':
const tem = '张三'
break;
case 'Search':
const tem = '李四'
break;
default:
break;
解决办法:两种
- 添加块级作用域 { } ,使用 { } 将 case 包裹起来
- 直接忽略 eslint 校验吧
switch (name) {
case 'zhangsan':{
const tem = '张三'
break;
}
case 'Search':
// eslint-disable-next-line no-case-declarations
const tem = '李四'
break;
default:
break;