【发布时间】:2021-07-13 04:00:44
【问题描述】:
在 Vue.JS 中,模板不需要使用this 来访问组件变量。 ESLint 的 Vue 扩展包含规则 vue/this-in-template 以在不必要地使用 this 时发出警告,如下例所示。
<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
但是,此规则是少数无法自动修复的规则之一。这是为什么呢?
【问题讨论】: