Skip to content

Import components inside setup #601

@qcp

Description

@qcp

Clear and concise description of the problem

Quite often there is a need to specify types for a component's ref variable.
To control behavior, such as a toggle, or receive some data.

Simplest example:

MyComponent.vue

<script setup lang="ts">
defineExpose({
  sayHi: () => alert('hi'),
});
</script>

<template>
  <h1>hi</h1>
</template>

App.vue

<script setup lang="ts">
// Now I have to import it manually
// It would be great if auto-import covered this need as well.
import MyComponent from './components/MyComponent.vue';

const myComp = ref<InstanceType<typeof MyComponent>>();
</script>

<template>
  <my-component ref="myComp" />

  <button @click="myComp?.sayHi()">Say Hi</button>
</template>

Current behavior
image

Project with reproduction here

Suggested solution

#562
Closed by author 🤷‍♂️

#527
Seems valid solution

Alternative

No response

Additional context

Related issue
unplugin/unplugin-auto-import#118
But it was closed without solution

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy