Skip to content

noVueThisInTemplate (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noVueThisInTemplate": "error"
}
}
}
}

Disallow this in Vue templates.

Vue templates can read the properties of the component directly. Writing this.count in a template does the same thing as writing count, so this only adds noise.

The rule doesn’t report this.name when writing name alone would mean something else, for example when a v-for or v-slot variable, or a function parameter, has the same name.

<template>
<a :href="this.url">{{ text }}</a>
</template>
<template>
<p>{{ this.text }}</p>
</template>
<template>
<button @click="this.count++">Add</button>
</template>
<template>
<a :href="url">{{ text }}</a>
<button @click="count++">Add</button>
<!-- `item` alone would be the `v-for` variable. -->
<p v-for="item in items">{{ this.item }}</p>
</template>