fix(nuxt): improve warning for invalid children of <Title> (#21613)

This commit is contained in:
Nozomu Ikuta 2023-06-18 06:37:05 +09:00 committed by GitHub
parent 64bccf37a5
commit 634829a08c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -149,12 +149,20 @@ export const Title = defineComponent({
name: 'Title', name: 'Title',
inheritAttrs: false, inheritAttrs: false,
setup: setupForUseMeta((_, { slots }) => { setup: setupForUseMeta((_, { slots }) => {
const title = slots.default?.()?.[0]?.children || null if (process.dev) {
if (process.dev && title && typeof title !== 'string') { const defaultSlot = slots.default?.()
console.error('<Title> can only take a string in its default slot.')
if (defaultSlot && (defaultSlot.length > 1 || typeof defaultSlot[0].children !== 'string')) {
console.error('<Title> can take only one string in its default slot.')
}
return {
title: defaultSlot?.[0]?.children || null
}
} }
return { return {
title title: slots.default?.()?.[0]?.children || null
} }
}) })
}) })