Vize

vue/this-in-template

テンプレートで不要な this. 参照を検出します。

既定の重大度 プリセット 自動修正 オプション
warning happy-path, nuxt, ecosystem, opinionated なし なし

適用範囲:Vue SFC のテンプレートと各ブロック。ルールに必要な script の文脈も例に含めています。

悪い例

テンプレートで直接使えるバインディングを this.message、this.className、this.handleClick と明示的に参照しています。

<template>
<div>{{ this.message }}</div>
<div :class="this.className"></div>
<button @click="this.handleClick()"></button>
</template>

良い例

message、className、handleClick を直接使います。文字列 'this.is.a.string' はメンバー参照ではないため残します。

<template>
<div>{{ message }}</div>
<div :class="className"></div>
<button @click="handleClick()"></button>
<div>{{ 'this.is.a.string' }}</div>
</template>

設定(Vite+)

import { defineConfig } from "@vizejs/vite-plugin/vite-plus";

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "vue/this-in-template": "warn"
    }
  },
});

設定したら vp run lint を実行します。

関連ページ