Max
Max

Reputation: 4879

Vue.js 3 declare a props with Array of Class

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 ?

Upvotes: 9

Views: 12907

Answers (2)

Pedro P. Camellon
Pedro P. Camellon

Reputation: 309

(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

Upvotes: 3

Vocalstorage
Vocalstorage

Reputation: 141

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,
     }
})  

Upvotes: 14

Related Questions