vue/v-on-handler-style
イベント handler の参照・関数形式を揃えます。
既定の重大度: warning
プリセット: nuxt, opinionated
自動修正: なし。修正内容を確認してください
適用範囲: Vue SFC のテンプレート・ブロック。必要な script の文脈も例に含めています。
オプション: ルール固有のオプションはありません。重大度とプリセットは設定できます。
設定(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({
lint: {
vize: {
"preset": "incremental",
"rules": {
"vue/v-on-handler-style": "warn"
}
},
},
});
vp run lint
悪い
イベント属性の中に変更処理や複数の文を直接記述しています。
<template>
<button @click="count++"></button>
<button @click="doThis(); doThat()"></button>
<button @click="foo = bar"></button>
</template>
良い
handler の参照を使うか、インライン処理が必要なら arrow / function 式で関数の境界を明示します。
<template>
<button @click="handler"></button>
<button @click="foo.bar"></button>
<button @click="() => count++"></button>
<button @click="function () { count++ }"></button>
</template>
良い例は上記の設定でこのルールの検出を避ける例です。他のルールでは検出される場合があります。