Skip to content

Commit 8ed14c8

Browse files
committed
support mixed prop syntax (close #1798)
1 parent 3a05b51 commit 8ed14c8

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/util/options.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,23 @@ function guardComponents (options) {
247247

248248
function guardProps (options) {
249249
var props = options.props
250-
var i
250+
var i, val
251251
if (_.isArray(props)) {
252252
options.props = {}
253253
i = props.length
254254
while (i--) {
255-
options.props[props[i]] = null
255+
val = props[i]
256+
if (typeof val === 'string') {
257+
options.props[val] = null
258+
} else if (val.name) {
259+
options.props[val.name] = val
260+
}
256261
}
257262
} else if (_.isPlainObject(props)) {
258263
var keys = Object.keys(props)
259264
i = keys.length
260265
while (i--) {
261-
var val = props[keys[i]]
266+
val = props[keys[i]]
262267
if (typeof val === 'function') {
263268
props[keys[i]] = { type: val }
264269
}

test/unit/specs/directives/internal/prop_spec.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,36 @@ if (_.inBrowser) {
438438
expect(el.textContent).toBe('AAA')
439439
})
440440

441+
it('mixed syntax', function () {
442+
new Vue({
443+
el: el,
444+
template: '<test :b="a" :c="d"></test>',
445+
data: {
446+
a: 'AAA',
447+
d: 'DDD'
448+
},
449+
components: {
450+
test: {
451+
props: [
452+
'b',
453+
{
454+
name: 'c',
455+
type: Number
456+
},
457+
{
458+
name: 'd',
459+
required: true
460+
}
461+
],
462+
template: '<p>{{b}}</p><p>{{c}}</p>'
463+
}
464+
}
465+
})
466+
expect(hasWarned(_, 'Missing required prop')).toBe(true)
467+
expect(hasWarned(_, 'Expected Number')).toBe(true)
468+
expect(el.textContent).toBe('AAA')
469+
})
470+
441471
it('should not overwrite default value for an absent Boolean prop', function () {
442472
var vm = new Vue({
443473
el: el,

0 commit comments

Comments
 (0)