Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/vdom/create-component.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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>');
})
})