Each slot passed to a component should have unique name

  • VUE_DUPLICATE_SLOT
  • Error
  • Medium
  • vue

This rule applies when multiple slots with the same name are passed to a component as the following:

  1. Two <template> slots of a component have v-slot directives with the same argument. In this case, the previous <template> is ignored. See Example 1 below.
  2. v-slot having fixed argument is used together with v-for on the same <template>. In this case, only the last iteration content is recognized as the slot. See Example 2 below.
  3. Child nodes not belonging to a <template> slot exist when the parent component has an explicit <template> for the default slot. Those extraneous nodes are ignored. See Example 3 below.

Noncompliant Code Example

View with compliant examples side by side
<template>
  <div>
    <!-- Example 1 -->
    <comp>
      <template v-slot:foo>
        Foo slot
      </template>
      <template v-slot:foo> <!-- VUE_DUPLICATE_SLOT alarm -->
        Bar slot
      </template>
    </comp>

    <!-- Example 2 -->
    <comp>
      <template v-for="item in list" v-slot:foo> <!-- VUE_DUPLICATE_SLOT alarm -->
        <div :key="item.id">
          {{ item.name }}
        </div>
      </template>
    </comp>

    <!-- Example 3 -->
    <comp>
      <template v-slot:default>
        <div>Default slot content 1</div>
      </template>
      <div>Default slot content 2</div> <!-- VUE_DUPLICATE_SLOT alarm -->
    </comp>
  </div>
</template>

Compliant Code Example

View with noncompliant examples side by side
<template>
  <div>
    <!-- Example 1 -->
    <comp>
      <template v-slot:foo>
        Foo slot
      </template>
      <template v-slot:bar>
        Bar slot
      </template>
    </comp>

    <!-- Example 2 -->
    <comp>
      <template v-slot:foo>
        <div v-for="item in list" :key="item.id">
          {{ item.name }}
        </div>
      </template>
    </comp>

    <!-- Example 3 -->
    <comp>
      <template v-slot:default>
        <div>Default slot content 1</div>
        <div>Default slot content 2</div>
      </template>
    </comp>
  </div>
</template>

Version

This rule was introduced in DeepScan 1.39.0.

See

Was this documentation helpful?