Skip to content

Commit

Permalink
fix(v-model): should generate component-specific code for tags with "…
Browse files Browse the repository at this point in the history
…is" attribute

fix #6066
  • Loading branch information
yyx990803 committed Jul 10, 2017
1 parent 8d66691 commit a1d1145
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,9 @@ function processAttrs (el) {
)
}
}
if (isProp || platformMustUseProp(el.tag, el.attrsMap.type, name)) {
if (!el.component && (
isProp || platformMustUseProp(el.tag, el.attrsMap.type, name)
)) {
addProp(el, name, value)
} else {
addAttr(el, name, value)
Expand Down
6 changes: 5 additions & 1 deletion src/platforms/web/compiler/directives/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ export default function model (
}
}

if (tag === 'select') {
if (el.component) {
genComponentModel(el, value, modifiers)
// component v-model doesn't need extra runtime
return false
} else if (tag === 'select') {
genSelect(el, value, modifiers)
} else if (tag === 'input' && type === 'checkbox') {
genCheckboxModel(el, value, modifiers)
Expand Down
35 changes: 35 additions & 0 deletions test/unit/features/directives/model-component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,41 @@ describe('Directive v-model component', () => {
}).then(done)
})

it('should work with native tags with "is"', done => {
const vm = new Vue({
data: {
msg: 'hello'
},
template: `
<div>
<p>{{ msg }}</p>
<input is="test" v-model="msg">
</div>
`,
components: {
test: {
props: ['value'],
template: `<input :value="value" @input="$emit('input', $event.target.value)">`
}
}
}).$mount()
document.body.appendChild(vm.$el)
waitForUpdate(() => {
const input = vm.$el.querySelector('input')
input.value = 'world'
triggerEvent(input, 'input')
}).then(() => {
expect(vm.msg).toEqual('world')
expect(vm.$el.querySelector('p').textContent).toEqual('world')
vm.msg = 'changed'
}).then(() => {
expect(vm.$el.querySelector('p').textContent).toEqual('changed')
expect(vm.$el.querySelector('input').value).toEqual('changed')
}).then(() => {
document.body.removeChild(vm.$el)
}).then(done)
})

it('should support customization via model option', done => {
const spy = jasmine.createSpy('update')
const vm = new Vue({
Expand Down

0 comments on commit a1d1145

Please sign in to comment.