yarn add eslint @eslint/js eslint-plugin-vue
- 在package.js增加eslint命令(执行npm run lint即可eslint检查):
"lint": "eslint"
- 在src同级目录下添加eslint规范文件eslint.config.js,文件规范内容如下:
import eslint from '@eslint/js'
import globals from 'globals'
import eslintPluginVue from 'eslint-plugin-vue'
export default [
{
ignores: [
'node_modules',
'dist',
'public',
],
},
eslint.configs.recommended,
...eslintPluginVue.configs['flat/recommended'],
{
languageOptions: {
globals: {
...globals.browser
}
}
},
{
files: ['**/*.vue'],
languageOptions: {
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: {
jsx: true,
},
},
},
rules: {
// 在这里追加 vue 规则
'vue/no-mutating-props': [
'error',
{
shallowOnly: true
}
]
}
},
{
rules: {
'no-console': 'off',
'vue/multi-word-component-names': 'off'
}
}
]