Vue項目中ESlint語法報錯問題的處理方法


 

首先在項目根目錄創建一個名叫.prettierrc的格式化配置項文件,文件內的格式為json格式。

semi: falae 為true 格式化在行尾加分號,false不加分號

singleQuote: true 為true表示格式化以單引號為主

{
  "semi": false,
  "singleQuote": true
}

 

 


 

禁用某項eslint規則:

在項目目錄打開 .eslintrc.js 文件

在rules對象添加報錯的屬性,並設置為0,表示禁用該項。

一般在報錯的error:  后面有個括號,把括號中的內容粘貼過來,放在reels中。

案例:

Failed to compile.

./src/components/Login.vue
Module Error (from ./node_modules/.pnpm/registry.npm.taobao.org/eslint-loader/2.2.1_eslint@5.16.0+webpack@4.41.2/node_modules/eslint-loader/index.js):
error: Extra semicolon (semi) at src/components/Login.vue:54:51:

以這個報錯為例: error 后面的括號中有個 semi 把這個semi復制一下,打開項目根目錄的.eslintrc.js 文件

module.exports = {
  root: true,
  env: {
    node: true
  },
  'extends': [
    'plugin:vue/essential',
    '@vue/standard'
  ],
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
  },
  parserOptions: {
    parser: 'babel-eslint'
  }
}

 這里的rules,在后面添加一行 'semi':0

module.exports = {
  root: true,
  env: {
    node: true
  },
  'extends': [
    'plugin:vue/essential',
    '@vue/standard'
  ],
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'semi':0
  },
  parserOptions: {
    parser: 'babel-eslint'
  }
}

這樣就可以禁用某項eslint語法檢測。

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM