-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Support for explicit import global components #13413
Comments
Would you provide a reproduction? I'm not sure what you mean. |
Not a bug. It's a feature request or question. In vue-router, we can use <script setup lang="ts">
import { RouterLink, RouterView } from 'vue-router'
</script>
<template>
<header>
<div class="wrapper">
<nav>
<RouterLink to="/">Home</RouterLink>
<RouterLink to="/about">About</RouterLink>
</nav>
</header>
<RouterView />
</template> see Which lib should I import when I use Can I write <script setup lang="ts">
import { NuxtLink } from 'nuxt3'
</script>
<template>
<header>
<div class="wrapper">
<nav>
<NuxtLink to="/">Home</NuxtLink>
<NuxtLink to="/about">About</NuxtLink>
</nav>
</header>
</template> |
You shouldn't have to import NuxtLink it will be auto imported by using the component. I have an example here https://stackblitz.com/edit/nuxt-starter-g2m6nk |
You can learn more about the auto-import in https://v3.nuxtjs.org/concepts/auto-imports |
What do you think @pi0 - would it be useful to expose a |
We use https://eslint.vuejs.org/rules/no-undef-components.html and all component should be registered locally. So I can't use auto import in our project. |
Seems a good idea @danielroe. We had same possibility with Nuxt2 (https://github.com/nuxt/components/blob/main/templates/components/index.js) Would be nice if we could also expose possible component names as an array as well. |
I think this will definitely be useful, especially for peeps using JSX components. At the moment, doing something like this actually works: // App.tsx
import { defineComponent } from 'vue';
export default defineComponent(() => {
return () => (
<NuxtLayout>
<NuxtPage />
</NuxtLayout>
)
}); but because there are no imports, TS actually complains with |
@baryla FYI, there are global types registered in |
@danielroe thanks for the reply. I just checked my // Generated by components discovery
declare module 'vue' {
export interface GlobalComponents {
'NuxtWelcome': typeof import("../../node_modules/nuxt3/dist/app/components/nuxt-welcome.vue")['default'],
'ClientOnly': typeof import("../../node_modules/nuxt3/dist/app/components/client-only")['default']
}
}
export {} I'm not sure if I should turn anything on in the settings? My When I created a component in btw. 👆 this is from a completely fresh installation of Nuxt. |
+1 |
My dev server hangs on specific routes on page reload when I import and use components imported from I was able to create a small reproduction of the issue, you can find it here: https://stackblitz.com/edit/nuxt-starter-azudzq?file=pages%2Findex.vue |
Did you find a way to do it, @xiaoxiangmoe? Right now having to import things from #imports or #app is the worst thing about Nuxt for me. In particular it messes with auto sorting of imports. |
Can we use
Additional context
We use https://eslint.vuejs.org/rules/no-undef-components.html and all component should be registered locally.
The text was updated successfully, but these errors were encountered: