vue.js - Vue 中的 ESLint 代码格式

标签 vue.js visual-studio-code eslint

我用 npm 和 vuejs/vue-cli 创建了一个项目。

我导入了 ESLint 扩展。

我的 package.json 文件中有 eslint 条目。

现在当我格式化我的代码时(右击,格式化代码),它完全毁坏了我的代码。

我要怎么做才能让 vscode 根据 ESLint 规则格式化?

enter image description here

enter image description here

enter image description here

但在网站上,ESLint 提示所有内容的格式不正确,因此从某种意义上说,它显然已安装并正在运行:

enter image description here

最佳答案

1)首先需要在VS code中安装ESLint扩展

此扩展使用 ESLint 库。如果您尚未在本地或全局安装 ESLint,请运行

npm install eslint //For a local install
 or 
npm install -g eslint //For a global install.

2) 然后,在 VS 代码中打开 Setting.json 文件。经过 文件-> 首选项-> 设置。

3) 添加以下设置。

 {
    "eslint.enable": true,
    "eslint.autoFixOnSave": true,
    "eslint.run": "onType",
    "eslint.options": {
        "extensions": [".js",".vue"]
    },
    "eslint.validate": [
        { "language": "vue", "autoFix": true }
    ]
}

4) 现在,检查您的 vue 文件。它将开始显示 linting 错误。如果没有,请重新启动 VS 代码。

关于vue.js - Vue 中的 ESLint 代码格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45852531/

相关文章:

css - Vue.js CSS 更改按钮 onClick to href 不起作用

angular - Visual Studio 代码和 Angular : how do I rename folders and component class?

javascript - VSCode 是否应该报告从编译中排除的 TS 文件的错误?

javascript - 默认加载eslint插件规则

javascript - Vue.js 可以使用 node-coap 库吗?

javascript - 使用 Vuetify v-data-table 组件时控制台输出警告

vue.js - 如何为我的 Vue 构建修复 'Browserslist: caniuse-lite is outdated'?

python - VS Code 在 MacOS 上未检测到 Python3 解释器

c# - 找不到模块 'eslint-config-defaults/configurations/eslint'

javascript - Webpack 在使用 npm 链接时给出 eslint 错误