JS.VUE.NO.DUPLICATE.ATTRIBUTES

Disallow duplication of attributes

When duplicate arguments exist, only the last one is valid. It's possibly mistakes.

Rule Details

This rule reports duplicate attributes. v-bind:foo directives are handled as the attributes foo.

{'vue/no-duplicate-attributes': ['error']}

Copy
<template>
  <!-- GOOD -->
  <MyComponent :foo="abc" />
  <MyComponent foo="abc" />
  <MyComponent class="abc" :class="def" />

  <!-- BAD -->
  <MyComponent :foo="abc" foo="def" />
  <MyComponent foo="abc" :foo="def" />
  <MyComponent foo="abc" foo="def" />
  <MyComponent :foo.a="abc" :foo.b="def" />
  <MyComponent class="abc" class="def" />
</template>

Options

Copy
{
  "vue/no-duplicate-attributes": ["error", {
    "allowCoexistClass": true,
    "allowCoexistStyle": true
  }]
}
  • allowCoexistClass (boolean) ... Enables v-bind:class directive can coexist with the plain class attribute. Default is true.
  • allowCoexistStyle (boolean) ... Enables v-bind:style directive can coexist with the plain style attribute. Default is true.

"allowCoexistClass": false, "allowCoexistStyle": false

{'vue/no-duplicate-attributes': ['error', {allowCoexistClass: false, allowCoexistStyle: false}]}

Copy
<template>
  <!-- BAD -->
  <MyComponent class="abc" :class="def" />
  <MyComponent style="abc" :style="def" />
</template>

The content on this page is adapted from the ESLint User Guide. Copyright © OpenJS Foundation and other contributors, www.openjsf.org. All rights reserved. https://eslint.org/docs/rules/