在初始化项目时有个选项Use ESLint to lint your code? (Y/n)
如果选择是yes,则有可能在你写.vue文件的js时会报以下错误:
✘ http://eslint.org/docs/rules/indent Expected indentation of 0 spaces but found 2
src\pages\Main.vue:87:1
export default {
^
✘ http://eslint.org/docs/rules/indent Expected indentation of 2 spaces but found 4
src\pages\Main.vue:88:1
name: 'Main',
^
✘ http://eslint.org/docs/rules/indent Expected indentation of 2 spaces but found 4
src\pages\Main.vue:89:1
data () {
^
✘ http://eslint.org/docs/rules/indent Expected indentation of 4 spaces but found 6
src\pages\Main.vue:90:1
return {
^
✘ http://eslint.org/docs/rules/indent Expected indentation of 6 spaces but found 8
src\pages\Main.vue:91:1
msg: 'Welcome to Your Vue.js App'
^
✘ http://eslint.org/docs/rules/indent Expected indentation of 4 spaces but found 6
src\pages\Main.vue:92:1
}
^
✘ http://eslint.org/docs/rules/indent Expected indentation of 2 spaces but found 4
src\pages\Main.vue:93:1
}
^
✘ http://eslint.org/docs/rules/indent Expected indentation of 0 spaces but found 2
src\pages\Main.vue:94:1
}
^
✘ 8 problems (8 errors, 0 warnings)
Errors:
8 http://eslint.org/docs/rules/indent
You may use special comments to disable some warnings.
Use // eslint-disable-next-line to ignore the next line.
Use /* eslint-disable */ to ignore all warnings in a file.复制代码
这个错误因为你设置了eslint,但你的js代码不规范的原因,其实错误已经很清晰,大多数就是缩进不规范,分号不需要等原因,很容易解决的,如果你不想有规范的js代码,可以重新初始化关掉eslint。
在bulid/webpack.base.conf.js里面有配置如下:
module: {
rules: [
...(config.dev.useEslint ? [createLintingRule()] : []),复制代码
点进config.dev.useEslint,发现在config/index.js里配置
useEslint: true, // 改为false即可。