Appearance
vue/define-props-destructuring
强制属性解构的样式一致
¥enforce consistent style for props destructuring
📖 规则详情
此规则强制使用一致的样式来处理 Vue 3 Composition API 属性,允许你选择是否需要解构。
¥This rule enforces a consistent style for handling Vue 3 Composition API props, allowing you to choose between requiring destructuring or prohibiting it.
默认情况下,此规则要求你在使用 defineProps 时使用解构语法,而不是将属性存储在变量中,并警告不要将 withDefaults 与解构结合使用。
¥By default, the rule requires you to use destructuring syntax when using defineProps instead of storing props in a variable and warns against combining withDefaults with destructuring.
此规则适用于 JavaScript 和 TypeScript 属性:
¥The rule applies to both JavaScript and TypeScript props:
🔧选项
¥🔧 Options
js
{
"vue/define-props-destructuring": ["error", {
"destructure": "always" | "never"
}]
}destructure- 设置属性的解构首选项。¥
destructure- Sets the destructuring preference for props"always"(默认) - 使用defineProps时需要解构,并警告不要将withDefaults与解构结合使用。¥
"always"(default) - Requires destructuring when usingdefinePropsand warns against usingwithDefaultswith destructuring"never"- 要求使用变量存储属性,并禁止解构。¥
"never"- Requires using a variable to store props and prohibits destructuring
"destructure": "never"
📚扩展阅读
¥📚 Further Reading
🚀版本
¥🚀 Version
此规则在 eslint-plugin-vue v10.1.0 中引入
¥This rule was introduced in eslint-plugin-vue v10.1.0
🔍代码实现
¥🔍 Implementation