Reputation: 1851
In Vue.JS, templates don't need to use this
to access component variables. The Vue extension for ESLint includes the rule vue/this-in-template to warn when this
is unnecessarily used, such as in the below example.
<template>
<img
v-if="this.type == 'image'"
:src="this.imageURL"
class="cardImage"
/>
</template>
Line 2: error Unexpected usage of 'this' vue/this-in-template
Line 3: error Unexpected usage of 'this' vue/this-in-template
However, this rule is one of only a few others that aren't automatically fixable. Why is that?
Upvotes: 1
Views: 197
Reputation: 138526
The implementation of vue/this-in-template
currently does not implement fix()
, which is required to auto-fix the error.
I think it's not implemented yet possibly because there might be some tricky examples (maybe dynamic property names) that require a non-trivial fix up. I also don't see any safety issues in removing this
from the template.
Upvotes: 1