Skip to content

useVueSlotsAsFunctions (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"useVueSlotsAsFunctions": "error"
}
}
}
}

Require the slots in this.$slots to be called as functions.

In Vue 3, each property of $slots is a function that returns the content of the slot. Code that treats a slot as the content itself, for example by reading its length, calling array methods on it, or spreading it into an array, doesn’t work. Call the slot to get its content instead.

See the Vue documentation for more information.

<script>
import { h } from "vue";
export default {
render() {
return h("div", this.$slots.default.filter(isVisible));
}
};
</script>
code-block.vue:6:33 lint/nursery/useVueSlotsAsFunctions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ This slot is used as its content instead of being called.

4 │ export default {
5 │ render() {
> 6 │ return h("div", this.$slots.default.filter(isVisible));
│ ^^^^^^^
7 │ }
8 │ };

ℹ In Vue 3, each property of $slots is a function that returns the content of the slot, so reading or iterating it directly doesn't work.

ℹ Call the slot to get its content, for example this.$slots.default().

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

<script>
import { h } from "vue";
export default {
render() {
return h("div", [...this.$slots.default]);
}
};
</script>
code-block.vue:6:37 lint/nursery/useVueSlotsAsFunctions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ This slot is used as its content instead of being called.

4 │ export default {
5 │ render() {
> 6 │ return h("div", [...this.$slots.default]);
│ ^^^^^^^
7 │ }
8 │ };

ℹ In Vue 3, each property of $slots is a function that returns the content of the slot, so reading or iterating it directly doesn't work.

ℹ Call the slot to get its content, for example this.$slots.default().

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

<script>
import { h } from "vue";
export default {
render() {
const children = this.$slots.default;
return h("div", children.length);
}
};
</script>
code-block.vue:6:34 lint/nursery/useVueSlotsAsFunctions ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

✖ This slot is used as its content instead of being called.

4 │ export default {
5 │ render() {
> 6 │ const children = this.$slots.default;
│ ^^^^^^^
7 │ return h("div", children.length);
8 │ }

ℹ In Vue 3, each property of $slots is a function that returns the content of the slot, so reading or iterating it directly doesn't work.

ℹ Call the slot to get its content, for example this.$slots.default().

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

<script>
import { h } from "vue";
export default {
render() {
const children = this.$slots.default();
const header = this.$slots.header && this.$slots.header();
return h("div", [header, children]);
}
};
</script>