Skip to content
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: improve the head API #41

Closed
chanlito opened this issue May 8, 2020 · 5 comments · Fixed by #43
Closed

feat: improve the head API #41

chanlito opened this issue May 8, 2020 · 5 comments · Fixed by #43
Assignees
Labels
enhancement New feature or request

Comments

@chanlito
Copy link

chanlito commented May 8, 2020

Currently according to the README useHead() is being used outside of the component.

Usually functions starting with useXXX are composition API used inside components.
Which to me, I think it might cause confusion.

I think the API would be cleaner like the following, but not sure if the implementation is possible.
Just giving my opinion.

import { defineComponent, head, useMeta } from 'nuxt-composition-api';

export default defineComponent({
  // this line is needed!
  head,
  setup() {
    // This will allow you to set the title in head - but won't allow you to read its state outside of this component.
    const { title } = useMeta()

    title.value = 'newSetTitle'
  },
})
@chanlito chanlito added the enhancement New feature or request label May 8, 2020
@mathe42
Copy link
Collaborator

mathe42 commented May 8, 2020

Yes it would be cleaner. If we can get your API we can also remove head. But that is currently not posible as far as I know...

@danielroe
Copy link
Member

I think we could produce a modified defineComponent that would have a number of use cases, including this one. Would need to be very careful with performance.

@mathe42
Copy link
Collaborator

mathe42 commented May 8, 2020

Maybe we can add a definePage wrapper that can handle head, asyncData.

@danielroe danielroe changed the title Regarding the head API feat: improve the head API May 8, 2020
danielroe added a commit that referenced this issue May 9, 2020
This improves the `useMeta()` helper by removing the need to pass `head` into `defineComponent`. Instead, a helper function is injected into components that can then be hooked into by `useMeta`.

BREAKING CHANGE: `useHead()` no longer exists and instead `useMeta` can be used directly within `setup`, as long as a minimal `head: {}` is defined in the component options.

_Note_: Work has already begun on composable hooks for `vue-meta` that will mean we don't need to define a minimal `head` object: see [here](5d0eb1ab60ce476ed8a97e97d4d409e74284df9b).

Closes #41
@katerlouis
Copy link

katerlouis commented Jul 1, 2021

I think we could produce a modified defineComponent that would have a number of use cases, including this one. Would need to be very careful with performance.

What other use cases are you talking about? I cannot find any information regarding a modified defineComponent in the docs

@mathe42
Copy link
Collaborator

mathe42 commented Jul 1, 2021

see https://github.com/nuxt-community/composition-api/blob/main/src/runtime/composables/component.ts we don't reexport the defineComponent function from @vue/composition-api but extend it with some logic for the head.

Other usecases / ideas got droped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants