更漂亮地格式化.vue

时间:2019-01-12 14:48:36

标签: vue.js visual-studio-code eslint prettier

.vue无法更好地使用VS Code扩展名。我的意思是如何设置漂亮的文件,使其与eslint集成并格式化Cmd+Shift+P -> Format Document上的.vue文件。 .eslintrc.js

module.exports = {
  root: true,
  env: {
    browser: true,
  },
  extends: [
    'plugin:vue/essential',
    'standard'
  ],
  plugins: [
    'vue'
  ]
}

3 个答案:

答案 0 :(得分:1)

您需要像这样在.eslintrc.js文件中定义这些规则:

module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: ["plugin:vue/essential", "@vue/prettier"],
  rules: {
    "no-console": process.env.NODE_ENV === "production" ? "error" : "off",
    "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
    "prettier/prettier": [
      "warn",
      {
        "singleQuote": true,
        "semi": false,
        "trailingComma": "none"
      }
    ]
  },
  parserOptions: {
    parser: "babel-eslint"
  }
};

答案 1 :(得分:0)

您可以在根目录中添加.prettierrc.json文件,然后

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

答案 2 :(得分:0)

更简单的方法是安装vetur required扩展名,然后添加.vscode> settings.json并添加以下

octref.vetur

enter image description here