Skip to content
← Back to rules

vue/no-multiple-slot-args 限制

An auto-fix is available for this rule.

它做了什么

禁止向作用域插槽传递多个参数。

为什么这是个问题?

用户必须按固定顺序使用这些参数,无法跳过不需要的参数。 例如,如果一个插槽传递了 5 个参数,但用户实际上只需要其中最后两个, 那么他们仍需声明全部 5 个参数才能使用最后两个。

更多详细信息请参见 vuejs/vue#9468

示例

此规则的 错误 代码示例:

vue
<script>
export default {
  render(h) {
    var children = this.$scopedSlots.default(foo, bar);
    var children = this.$scopedSlots.default(...foo);
  },
};
</script>

此规则的 正确 代码示例:

vue
<script>
export default {
  render(h) {
    var children = this.$scopedSlots.default();
    var children = this.$scopedSlots.default(foo);
    var children = this.$scopedSlots.default({ foo, bar });
  },
};
</script>

如何使用

要通过配置文件或 CLI 启用 此规则,可以使用:

json
{
  "plugins": ["vue"],
  "rules": {
    "vue/no-multiple-slot-args": "error"
  }
}
bash
oxlint --deny vue/no-multiple-slot-args --vue-plugin

参考资料