简体   繁体   English

Vue.js lint 强制组件为单行

[英]Vue.js lint forces component to a single line

I have a component in Vue template我在 Vue 模板中有一个组件

 <MyComponent
  class='class'
  someattribute='...'
  @event='eventListener'
/>

When I try to run lint it automatically reformats my code to following当我尝试运行 lint 时,它会自动将我的代码重新格式化为以下内容

 <MyComponent class='class' someattribute='...' @event='eventListener' />

I'm trying to disable it from doing so but can't find any corresponding rule.我正在尝试禁用它,但找不到任何相应的规则。 Any ideas how to avoid this?任何想法如何避免这种情况?

I just want it to stay however I write it and disable any rules regarding it.我只是希望它保留下来,但是我编写它并禁用有关它的任何规则。

you should not do this, single line props are recommended by Vue officially: https://v2.vuejs.org/v2/style-guide/#Multi-attribute-elements-strongly-recommended你不应该这样做,Vue官方推荐单行道具: https ://v2.vuejs.org/v2/style-guide/#Multi-attribute-elements-strongly-recommended

If you really want to change it.如果你真的想改变它。

  • in your package.json file, find if there is a eslintConfig在你的package.json文件中,查找是否有eslintConfig

    • if it has, add this config in its rules : "vue/max-attributes-per-line": "off"如果有,请在其rules中添加此配置: "vue/max-attributes-per-line": "off"
  • if no eslintConfig , you can add one.如果没有eslintConfig ,你可以添加一个。 the default config should look like this:默认配置应如下所示:

"eslintConfig": {
//... other config
       "rules": {
      "vue/max-attributes-per-line": "off"
    }
  },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM