9

I try to define my component props where type is Array

But it not working...

import { Person } from '...'
export default defineComponent({
    props: {
        people: Array<Person>
    }
})
export class Person {
...
}

How to declare it correctly ?

2 Answers 2

14

use Proptype imported from 'vue'

import { Person } from '...'
import { defineComponent, PropType } from 'vue';
    
export default defineComponent({
     props: {
        people: Array as PropType<Array<Person>>,
        default: undefined,
     }
})  
Sign up to request clarification or add additional context in comments.

Comments

3

(Vue v3.0.4)

Use PropType:

import { Person } from '...'
import { defineComponent } from 'vue';
import type { PropType } from 'vue'
    
export default defineComponent({
     props: {
        people: Array as PropType<Array<Person>>,
        default: () => [],
     }
})

Ref: https://vuejs.org/api/utility-types.html#proptype-t

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.