【问题标题】:Why isn't the vue/this-in-template ESLint rule automatically fixable?为什么 vue/this-in-template ESLint 规则不能自动修复?
【发布时间】: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

但是,此规则是少数无法自动修复的规则之一。这是为什么呢?

【问题讨论】:

    标签: vue.js eslint


    【解决方案1】:

    implementation of vue/this-in-template 目前没有实现自动修复错误所需的fix()

    我认为它尚未实现,可能是因为可能有一些棘手的示例(可能是动态属性名称)需要进行重要的修复。我也没有看到从模板中删除 this 的任何安全问题。

    【讨论】:

      猜你喜欢
      • 2018-01-08
      • 2021-10-17
      • 2015-12-20
      • 2017-03-24
      • 2020-08-26
      • 2021-12-10
      • 1970-01-01
      • 2020-11-03
      • 2019-09-27
      相关资源
      最近更新 更多