Vue: Prop validation, mix of array and object hash syntax

Created on 12 Nov 2015  ·  3Comments  ·  Source: vuejs/vue

After searching I couldn't find if this was already suggested and discounted, but at the moment when we can specify component props with a simple array of strings or complex object hash.

I think I might be useful if we could mix the two:

props: [
    'propA',
    'propB',
    {
        name: 'propC',
        type: Number,
        default: 100
    },
    'propD'
]

I often find I have props in an array of strings, and at a later stage need to add a prop which has validation. Meaning I have to concert the array of strings to a hash.

Most helpful comment

I'm getting the same error, when putting the props-example from the test (https://github.com/vuejs/vue/commit/8ed14c8e4b0c896c59c92455b2b7aa95214382c9#diff-2092e089df2ae66b53f34b1d728f3acc) in my component:

props: [ 'b', { name: 'c', type: Number }, { name: 'd', required: true } ],

All 3 comments

Is this feature supported in v2?
I've tried it and got the warning: props must be strings when using array syntax.

I'm getting the same error, when putting the props-example from the test (https://github.com/vuejs/vue/commit/8ed14c8e4b0c896c59c92455b2b7aa95214382c9#diff-2092e089df2ae66b53f34b1d728f3acc) in my component:

props: [ 'b', { name: 'c', type: Number }, { name: 'd', required: true } ],

Is there an accepted practice/answer to this issue?

Was this page helpful?
0 / 5 - 0 ratings