Are you an LLM? You can read better optimized documentation at /docs/guide/usage/linter/rules/vue/valid-define-options.md for this page in Markdown format
vue/valid-define-options Correctness
作用
强制正确使用 defineOptions 编译器宏。
为什么这很糟糕?
defineOptions 是 <script setup> 的编译器宏。它必须以一个单独的对象字面量调用,其中包含可在编译时求值的组件选项。诸如引用本地声明的变量、声明 props/emits/expose/slots、不传参数调用,或传入类型参数等误用,都会导致编译器无法处理。
示例
以下是此规则的错误代码示例:
vue
<script setup>
defineOptions(); // 无选项对象
defineOptions({ name: "A" });
defineOptions({ name: "B" }); // 多次调用
defineOptions({ props: { msg: String } }); // 请改用 `defineProps()`
</script>以下是此规则的正确代码示例:
vue
<script setup>
defineOptions({ name: "foo", inheritAttrs: false });
</script>How to Use
To enable this rule using the config file or in the CLI, you can use:
json
{
"plugins": ["vue"],
"rules": {
"vue/valid-define-options": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["vue"],
rules: {
"vue/valid-define-options": "error",
},
});bash
oxlint --deny vue/valid-define-options --vue-plugin版本
此规则添加于 v1.67.0。
