Vize

script/no-unstable-nested-components

禁止在 setup 或 render 函数内定义组件。

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

适用范围:Vue SFC 中的 JS/TS 脚本;示例展示对应的 Options API 或 script setup 形式。

错误示例

defineComponent 在父组件的 setup() 内运行,每次执行 setup 都创建新的 Child 组件定义。

<script lang="ts">
import { defineComponent } from "vue";
export default { setup() { const Child = defineComponent({ render() { return null; } }); return { Child }; } };
</script>

正确示例

Child 定义移到模块作用域,setup() 返回已存在的定义。

<script lang="ts">
import { defineComponent } from "vue";
const Child = defineComponent({ render() { return null; } });
export default { setup() { return { Child }; } };
</script>

配置(Vite+)

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

export default defineConfig({}).withVue({
  linter: {
    "preset": "incremental",
    "rules": {
      "script/no-unstable-nested-components": "warn"
    }
  },
});

然后运行 vp run lint。

相关页面