Vize

vapor/no-vue-lifecycle-events

禁止 @vue:xxx 元素生命周期事件(Vapor 不支持)。

默认严重程度 预设 自动修复 选项
error happy-path, nuxt, ecosystem, opinionated 不支持 无

适用范围:Vue SFC 模板和代码块,包括规则所需的脚本上下文。

错误示例

输入框使用了 @vue:mounted 模板生命周期事件。

<template>
  <input @vue:mounted="focusInput" />
</template>

正确示例

onMounted 通过受支持的脚本生命周期钩子访问具名模板引用,并聚焦输入框。

<script setup lang="ts" vapor>
const input = useTemplateRef<HTMLInputElement>("input");

onMounted(() => {
  input.value?.focus();
});
</script>

<template>
  <input ref="input" />
</template>

配置(Vite+)

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

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "vapor/no-vue-lifecycle-events": "error"
    }
  },
});

然后运行 vp run lint。

相关页面