Skip to content

Commit 1f77606

Browse files
committed
respect default data value for absent Boolean prop (fix vuejs#1020)
1 parent 7b1c2f4 commit 1f77606

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/compiler/compile-props.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,14 @@ module.exports = function compileProps (el, propOptions) {
9292

9393
function makePropsLinkFn (props) {
9494
return function propsLinkFn (vm, el) {
95+
// store resolved props info
96+
vm._props = {}
9597
var i = props.length
9698
var prop, path, options, value
9799
while (i--) {
98100
prop = props[i]
99101
path = prop.path
102+
vm._props[path] = prop
100103
options = prop.options
101104
if (prop.raw === null) {
102105
// initialize absent prop

src/instance/compile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,11 +182,11 @@ exports._cleanup = function () {
182182
// observing the same object, but that seems to be a
183183
// reasonable responsibility for the user rather than
184184
// always throwing an error on them.
185-
this._watchers =
186185
this.$el =
187186
this.$parent =
188187
this.$root =
189188
this.$children =
189+
this._watchers =
190190
this._directives = null
191191
// call the last hook...
192192
this._isDestroyed = true

src/instance/scope.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ exports._initData = function () {
5353
if (optionsData) {
5454
this._data = optionsData
5555
for (var prop in propsData) {
56-
if (
57-
!optionsData.hasOwnProperty(prop) ||
58-
propsData[prop] !== undefined
59-
) {
56+
if (this._props[prop].raw !== null) {
6057
optionsData.$set(prop, propsData[prop])
6158
}
6259
}

test/unit/specs/directives/prop_spec.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,5 +403,27 @@ if (_.inBrowser) {
403403
expect(vm.msg).toBe('hi!')
404404
expect(el.textContent).toBe('ho!')
405405
})
406+
407+
it('should not overwrite default value for an absent Boolean prop', function () {
408+
var vm = new Vue({
409+
el: el,
410+
template: '<test></test>',
411+
components: {
412+
test: {
413+
props: {
414+
prop: Boolean
415+
},
416+
data: function () {
417+
return {
418+
prop: true
419+
}
420+
},
421+
template: '{{prop}}'
422+
}
423+
}
424+
})
425+
expect(vm.$children[0].prop).toBe(true)
426+
expect(vm.$el.textContent).toBe('true')
427+
})
406428
})
407429
}

0 commit comments

Comments
 (0)