script/no-deprecated-destroyed-lifecycle
禁止已弃用的 destroyed 和 beforeDestroy 生命周期钩子。
| 默认严重程度 | 预设 | 自动修复 | 选项 |
|---|---|---|---|
error |
essential, happy-path, ecosystem, nuxt, opinionated |
支持 | 无 |
适用范围:Vue SFC 中的 JS/TS 脚本;示例展示对应的 Options API 或 script setup 形式。
错误示例
定时器清理使用了已移除的 Vue 2 生命周期选项 beforeDestroy。
<script lang="ts">
export default { beforeDestroy() { clearTimeout(this.timer); } };
</script>
正确示例
将钩子重命名为 beforeUnmount,在 Vue 3 生命周期名称下保留清理函数体。
<script lang="ts">
export default { beforeUnmount() { clearTimeout(this.timer); } };
</script>
配置(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"script/no-deprecated-destroyed-lifecycle": "error"
}
},
});
然后运行 vp run lint。