跳至内容

vue/no-restricted-component-options

禁止使用特定组件选项

📖 规则详细信息

此规则允许您指定不想在应用程序中使用的组件选项。

🔧 选项

此规则接受字符串列表,其中每个字符串都是要限制的组件选项名称或模式

json
{
  "vue/no-restricted-component-options": ["error", "init", "beforeCompile", "compiled", "activate", "ready", "/^(?:at|de)tached$/"]
}
正在加载...

此外,您可以使用数组来指定对象属性的路径。

例如:[ "error", ["props", "/.*/", "twoWay"] ]

正在加载...

您可以使用 "*" 来匹配所有属性,包括计算键。

例如:[ "error", ["props", "*", "twoWay"] ]

正在加载...

或者,该规则也接受对象。

json
{
  "vue/no-restricted-component-options": ["error",
    {
      "name": "init",
      "message": "Use \"beforeCreate\" instead."
    },
    {
      "name": "/^(?:at|de)tached$/",
      "message": "\"attached\" and \"detached\" is deprecated."
    },
    {
      "name": ["props", "/.*/", "twoWay"],
      "message": "\"props.*.twoWay\" cannot be used."
    }
  ]
}

可以为对象指定以下属性。

  • name ... 指定组件选项名称或模式,或通过其数组指定路径。
  • message ... 指定可选的自定义消息。

🚀 版本

此规则是在 eslint-plugin-vue v7.0.0 中引入的

🔍 实现