-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow automatic injection of head()
into components
#43
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/nuxt-community/composition-api/auv8mou50 |
When I use defineComponent in all of my components I have to.Import it directly from @vue/composition-api but I want one import. I think renaming it to something like Head does only Work on components in the Page folder. |
I think This is a drop-in replacement for Do you have a view from DX perspective @chanlito? |
src/component.ts
Outdated
): ReturnType<typeof define> | ||
|
||
export function defineComponent(options: any) { | ||
const reactiveHead = reactive<MetaInfo>({}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ssrRef?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your thinking...?
@@ -0,0 +1 @@ | |||
declare module 'defu' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to go. defu
has types but for some reason rollup wasn't recognising them until I edited its package.json
.
src/component.ts
Outdated
if (!vm) throw new Error('useMeta must be called within a component.') | ||
|
||
const { head } = vm.$options | ||
if (!head || !(head instanceof Function)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does vm.$options
has head
property if I set one in my nuxt.config.js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is per-component.
We can add a value to the Option so we can check if your defineComponent was used |
This improves the
useMeta()
helper by removing the need to passhead
intodefineComponent
. Instead, a helper function is injected into components that can then be hooked into byuseMeta
.BREAKING CHANGE:
useHead()
no longer exists and insteaduseMeta
can be used directly withinsetup
, as long as a minimalhead: {}
is defined in the component options.Note: Work has already begun on composable hooks for
vue-meta
that will mean we don't even need to define a minimalhead
object: see here.TODO:
useMeta
closes #41