Variables declared in a Vue template should be used

  • VUE_UNUSED_DECL_IN_TEMPLATE
  • Code Quality
  • Low
  • vue

This rule applies when variables declared in a Vue template are not used.

In a Vue template, variables are declared in the following positions:

  1. v-for directives
  2. slot-scope attributes

For maintainability, it is recommended to remove unused variables. Also, it might be a mistake that a programmer forgets to use the declared variables.

Noncompliant Code Example

View with compliant examples side by side
<template>
  <div>
    <div v-for="(item, index) in items" key="index">  <!-- VUE_UNUSED_DECL_IN_TEMPLATE alarm because variable 'index' is never used. -->
      {{ item.value }}
    </div>
  </div>
</template>

Compliant Code Example

View with noncompliant examples side by side
<template>
  <div>
    <div v-for="(item, index) in items" :key="index">
      {{ item.value }}
    </div>
  </div>
</template>

Version

This rule was introduced in DeepScan 1.15.0-beta.

See

Was this documentation helpful?