Skip to content

Commit

Permalink
fix: v-on="object" listeners should fire after high-priority ones
Browse files Browse the repository at this point in the history
fix #6805
  • Loading branch information
yyx990803 committed Oct 13, 2017
1 parent 5665eaf commit 08a7fb5
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/core/instance/render-helpers/bind-object-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function bindObjectListeners (data: any, value: any): VNodeData {
for (const key in value) {
const existing = on[key]
const ours = value[key]
on[key] = existing ? [].concat(ours, existing) : ours
on[key] = existing ? [].concat(existing, ours) : ours
}
}
}
Expand Down
43 changes: 42 additions & 1 deletion test/unit/features/directives/on.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ describe('Directive v-on', () => {
const mouseup = jasmine.createSpy('mouseup')
const mousedown = jasmine.createSpy('mousedown')

var vm = new Vue({
vm = new Vue({
el,
template: `
<foo-button
Expand Down Expand Up @@ -798,6 +798,47 @@ describe('Directive v-on', () => {
expect(mousedown.calls.count()).toBe(1)
})

// #6805 (v-on="object" bind order problem)
it('object syntax (no argument): should fire after high-priority listeners', done => {
const MyCheckbox = {
template: '<input type="checkbox" v-model="model" v-on="$listeners">',
props: {
value: false
},
computed: {
model: {
get () {
return this.value
},
set (val) {
this.$emit('input', val)
}
}
}
}

vm = new Vue({
el,
template: `
<div>
<my-checkbox v-model="check" @change="change"></my-checkbox>
</div>
`,
components: { MyCheckbox },
data: {
check: false
},
methods: {
change () {
expect(this.check).toBe(true)
done()
}
}
})

vm.$el.querySelector('input').click()
})

it('warn object syntax with modifier', () => {
new Vue({
template: `<button v-on.self="{}"></button>`
Expand Down

0 comments on commit 08a7fb5

Please sign in to comment.