解决Vue项目报错:Expected indentation of 2 spaces but found 4. eslint(indent) [8, 1]的方法

报错如下

解决Vue项目报错:Expected indentation of 2 spaces but found 4. eslint(indent) [8, 1]的方法_vue.js
解决Vue项目报错:Expected indentation of 2 spaces but found 4. eslint(indent) [8, 1]的方法_配置文件_02

解决Vue项目报错:Expected indentation of 2 spaces but found 4. eslint(indent) [8, 1]的方法_问题分析_03

问题分析

明显从图中可以以看出问题是使用 ESLint 插件导致的

作为一个代码规范插件,ESLint 限定缩进是 2 个空格,而我们一般使用 Tab 键的缩进是 4 个空格

解决办法

打开 .eslintrc.js 配置文件,加上下面这行配置 然后我们就可以看到原来的报错没有了

'indent': ['off', 2]

解决Vue项目报错:Expected indentation of 2 spaces but found 4. eslint(indent) [8, 1]的方法_缩进_04