vue3 函数式组件调试报警 Non-function value encountered for default slot

2023-01-14 09:33:17 浏览数 (1)

开发调试报警

[Vue warn]: Non-function value encountered for default slot. Prefer function slots for better performance.

原因

声明函数式组件时插槽传值时使用了非函数类型的值

代码语言:javascript复制
const component = (props: any) => {
    return h(
        MyComponent1,
        props,
        h(MyComponent2)
    )
}

解决

改写成如下形式即可

代码语言:javascript复制
const component = (props: any) => {
    return h(
        MyComponent1,
        props,
        () => h(MyComponent2)
    )
}

0 人点赞