JS.VUE.THIS.IN.TEMPLATE

Disallow usage of 'this' in template

Rule Details

This rule aims at preventing usage of this in Vue templates.

{'vue/this-in-template': ['error']}

Copy
<template>
  <!-- GOOD -->
  <a :href="url">
    {{ text }}
  </a>

  <!-- BAD -->
  <a :href="this.url">
    {{ this.text }}
  </a>
</template>

Options

Copy
{
  "vue/this-in-template": ["error", "always" | "never"]
}
  • "always" ... Always use this while accessing properties from Vue.
  • "never" (default) ... Never use this keyword in expressions.

"always"

{'vue/this-in-template': ['error', 'always']}

Copy
<template>
  <!-- GOOD -->
  <a :href="this.url">
    {{ this.text }}
  </a>

  <!-- BAD -->
  <a :href="url">
    {{ text }}
  </a>
</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/