2

How can I register a component in <script setup>?

img

2
  • Isn't that in the documentation? vuejs.org/v2/guide/components-registration.html Commented Sep 21, 2020 at 6:25
  • 3
    OP is using <script SETUP> (Vue 3) not <script> Commented Nov 21, 2020 at 20:05

1 Answer 1

4

Updated answer:

During the alpha stages of <script setup>'s implementation, component registration was done by exporting the component definition.

With the current officially released version (3.2.x), importing the component definition as you've done correctly registers the component:

<script setup>
import HiButton from '@/components/hive/button/index.vue' ✅
</script>

demo 1


Old answer that worked for alpha version of <script setup> in 30-SEP-2020:

According to the RFC, your <script setup> block needs to export the component like this:

<script setup>
export { default as HiButton } from '@/components/hive/button/index.vue'
</script>

demo 2

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.