Skip to content

vue/prefer-prop-type-boolean-first

强制 Boolean 在组件 prop 类型中排在第一位

  • 💡 此规则报告的某些问题可由编辑器 suggestions 手动修复。

📖 规则详情

在组件中声明属性的类型时,我们可以使用数组样式来接受多种类型。

¥When declaring types of a property in component, we can use array style to accept multiple types.

在模板中使用组件时,如果其值为 true,我们可以使用简写样式的属性。

¥When using components in template, we can use shorthand-style property if its value is true.

但是,如果某个属性允许 BooleanString,而我们在其他地方以简写形式使用它,则不同的类型顺序可能会引入不同的行为:如果 Boolean 先出现,则为 true;如果 String 先出现,则为 ""(空字符串)。

¥However, if a property allows Boolean or String and we use it with shorthand form in somewhere else, different types order can introduce different behaviors: If Boolean comes first, it will be true; if String comes first, it will be "" (empty string).

参见 此演示

¥See this demo.

Now loading...

👫相关规则

¥👫 Related Rules

🚀版本

¥🚀 Version

此规则在 eslint-plugin-vue v8.6.0 中引入

¥This rule was introduced in eslint-plugin-vue v8.6.0

🔍代码实现

¥🔍 Implementation

eslint-plugin-vue v10.1 中文网 - 粤ICP备13048890号