vapor/no-vue-lifecycle-events
Vapor が対応しない要素の @vue:* lifecycle event を検出します。
既定の重大度: error
プリセット: happy-path, nuxt, ecosystem, opinionated
自動修正: なし。修正内容を確認してください
適用範囲: Vue SFC のテンプレート・ブロック。必要な script の文脈も例に含めています。
オプション: ルール固有のオプションはありません。重大度とプリセットは設定できます。
設定(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({
lint: {
vize: {
"preset": "incremental",
"rules": {
"vapor/no-vue-lifecycle-events": "error"
}
},
},
});
vp run lint
悪い
input にテンプレートの @vue:mounted を指定しています。
<template>
<input @vue:mounted="focusInput" />
</template>
良い
script の onMounted からテンプレートの ref を参照し、input にフォーカスします。
<script setup lang="ts" vapor>
const input = useTemplateRef<HTMLInputElement>("input");
onMounted(() => {
input.value?.focus();
});
</script>
<template>
<input ref="input" />
</template>
良い例は上記の設定でこのルールの検出を避ける例です。他のルールでは検出される場合があります。