Skip to content
Closed
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
4 changes: 3 additions & 1 deletion src/core/vdom/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,9 @@ 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
// check if prop is defined, if not, attrs will be used
const propOrAttrKey = options.props && options.props[prop] ? 'props' : 'attrs'
;(data[propOrAttrKey] || (data[propOrAttrKey] = {}))[prop] = data.model.value
const on = data.on || (data.on = {})
const existing = on[event]
const callback = data.model.callback
Expand Down
21 changes: 21 additions & 0 deletions test/unit/features/directives/model-component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,27 @@ describe('Directive v-model component', () => {
expect(vm.text).toBe('foo o')
})


it('adds value to $attrs if no prop is defined', () => {
const Test = {
render: () => {}
}

const vm = new Vue({
components: {
Test
},
data () {
return {
value: 'value'
}
},
template: '<test v-model="value" ref="test" />'
}).$mount()

expect(vm.$refs.test.$attrs.value).toEqual(vm.value)
})

// #8436
it('should not double transform mode props', () => {
const BaseInput = {
Expand Down