10

Just learning Vue and TypeScript with class based components, my single file component looks like this:

<template>
    ...
    <div>
        <contact-component v-bind:key="c.id" v-for="c in contacts">
        </contact-component>
    </div>
</template>

<script lang="ts">
import ContactComponent from "./Contact.vue";
import { Component, Vue } from 'vue-property-decorator'

@Component
export default class ContactsComponent extends Vue {
    data() {...}
    components = { ContactComponent }
}
</script>

It generates the following error:

Unknown custom element: - did you register the component correctly?

Obviously my registration of the component does not work, but I have no idea how to fix this in TypeScript. What's the correct way to register ContactComponent so that it can be used in the above template?

1 Answer 1

13

like this


@Component({
  components: { ContactComponent }
})
export default class ContactsComponent extends Vue {}
Sign up to request clarification or add additional context in comments.

2 Comments

Are there any docs where I could have figured this out myself?
perhaps the example in Github. github.com/vuejs/vue-class-component/blob/master/example/src/… . it isn't explicit

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.