Skip to content

Commit

Permalink
fix(v-model): add value to $attrs if not defined in props (#9331)
Browse files Browse the repository at this point in the history
fix #9330
  • Loading branch information
lbogdan authored and yyx990803 committed Feb 4, 2019
1 parent 0fb03b7 commit 66fd3c8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/vdom/create-component.js
Expand Up @@ -250,7 +250,8 @@ function mergeHook (f1: any, f2: any): Function {
function transformModel (options, data: any) {
const prop = (options.model && options.model.prop) || 'value'
const event = (options.model && options.model.event) || 'input'
;(data.props || (data.props = {}))[prop] = data.model.value
const addTo = (options.props && prop in options.props) ? 'props' : 'attrs'
;(data[addTo] || (data[addTo] = {}))[prop] = data.model.value
const on = data.on || (data.on = {})
const existing = on[event]
const callback = data.model.callback
Expand Down
26 changes: 26 additions & 0 deletions test/unit/features/directives/model-component.spec.js
Expand Up @@ -204,4 +204,30 @@ describe('Directive v-model component', () => {
expect(triggerCount).toBe(1)
document.body.removeChild(vm.$el)
})

// #9330
it('should add value to $attrs if not defined in props', () => {
const TestComponent = {
inheritAttrs: false,
render (h) {
return h('div', this.$attrs.value)
}
}

const vm = new Vue({
components: {
TestComponent
},
template: `
<div>
<test-component v-model="val"/>
</div>
`,
data: {
val: 'foo'
}
}).$mount()

expect(vm.$el.innerHTML).toBe('<div>foo</div>');
})
})

0 comments on commit 66fd3c8

Please sign in to comment.