fix(model): fix static input type being overwritten by v-bind object (#7819)

fix #7811
This commit is contained in:
Hiroki Osame 2018-03-14 00:05:58 +09:00 committed by Evan You
parent 6dd73e9ee4
commit a6169d1eb7
2 changed files with 12 additions and 1 deletions

View File

@ -34,7 +34,7 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) {
if (map[':type'] || map['v-bind:type']) { if (map[':type'] || map['v-bind:type']) {
typeBinding = getBindingAttr(el, 'type') typeBinding = getBindingAttr(el, 'type')
} }
if (!typeBinding && map['v-bind']) { if (!map.type && !typeBinding && map['v-bind']) {
typeBinding = `(${map['v-bind']}).type` typeBinding = `(${map['v-bind']}).type`
} }

View File

@ -337,4 +337,15 @@ describe('Directive v-model checkbox', () => {
expect(vm.$el.children[1].textContent).toBe('false') expect(vm.$el.children[1].textContent).toBe('false')
}).then(done) }).then(done)
}) })
// #7811
it('type should not be overwritten by v-bind', () => {
const vm = new Vue({
data: {
test: true
},
template: '<input type="checkbox" v-model="test" v-bind="$attrs">'
}).$mount()
expect(vm.$el.type).toBe('checkbox')
})
}) })