useVueSlotsAsFunctions (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Rule available since:
v2.6.5 - Diagnostic Category:
lint/nursery/useVueSlotsAsFunctions - This rule doesn’t have a fix.
- The default severity of this rule is error.
- This rule belongs to the following domains:
- Sources:
- Same as
vue/require-slots-as-functions
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "useVueSlotsAsFunctions": "error" } } }}Description
Section titled “Description”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.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”<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>Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.