-
Notifications
You must be signed in to change notification settings - Fork 33
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
When using serializer.types, resolveComponent does not work and instead components have to be manually imported #550
Comments
Would you try not importing |
Do you mean without the line |
yes. |
Unfortunately, that didn't work either :( |
@toddpadwick I could make it work for component-name strings by making the desired components global in the nuxt config: components: {
dirs: [
// the base components directory didn't seem to work
// "~/components",
"~/components/00_base",
"~/components/01_atoms",
"~/components/02_molecules",
"~/components/03_organisms",
"~/components/04_layout",
{
path: "~/components/04_sections",
global: true,
},
],
}, @danielroe what I can't figure out is dynamic imports from variable names: const serializers = {
types: {
// works with global components when their names are available as strings
oneComponent: resolveComponent("FurtherQuestions"),
// doesn't work since component name gets resolved at runtime (?)
twoComponent: (props) => resolveComponent(props.title)
},
}; |
Found a working solution for the second problem: const serializers = {
types: {
// the import part is the `h()` render function
myType: (props) => h(resolveComponent(props.title), { props }),
}
},
}; |
If Nuxt can't know at build time which components you need, then you should mark them as global so they will all be built and available at runtime. |
@danielroe would you mind keeping this issue open? At least @toddpadwick and me tried using the docs in their current form and ended up having problems, I suppose there's some potential in being more clear on the different ways/use cases :) |
Of course! Good point. |
Version
module: 1.4.1
nuxt: 3-rc.11
When using the serializer, based on the docs, it seems the following should be possible:
However, it returns the following error:
The only way I have managed to get this to work, is by importing the component manually, like so:
The text was updated successfully, but these errors were encountered: