Skip to content

vue/no-required-prop-with-default

强制使用默认值的 props 为可选

  • ⚙️ 此规则包含在 "plugin:vue/vue2-recommended"*.configs["flat/vue2-recommended"]"plugin:vue/recommended"*.configs["flat/recommended"] 中。
  • 🔧命令行 上的 --fix 选项可以自动修复此规则报告的一些问题。

    ¥🔧 The --fix option on the command line can automatically fix some of the problems reported by this rule.

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

    ¥💡 Some problems reported by this rule are manually fixable by editor suggestions.

📖 规则详情

如果 prop 声明了默认值,无论是否需要,我们都可以实际使用时跳过它。在这种情况下,将应用默认值。因此,具有默认值的必需 prop 本质上与可选 prop 相同。此规则强制所有具有默认值的 props 为可选。

¥If a prop is declared with a default value, whether it is required or not, we can always skip it in actual use. In that situation, the default value would be applied. So, a required prop with a default value is essentially the same as an optional prop. This rule enforces all props with default values to be optional.

Now loading...
Now loading...

🔧选项

¥🔧 Options

json
{
  "vue/no-required-prop-with-default": ["error", {
    "autofix": false,
  }]
}
  • "autofix" ...如果是 true,则启用自动修复。(默认:false

    ¥"autofix" ... If true, enable autofix. (Default: false)

👫相关规则

¥👫 Related Rules

🚀版本

¥🚀 Version

此规则是在 eslint-plugin-vue v9.6.0 中引入的

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

🔍代码实现

¥🔍 Implementation

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