Explorar o código

fix: v-on="object" listeners should fire after high-priority ones

fix #6805
Evan You %!s(int64=8) %!d(string=hai) anos
pai
achega
08a7fb539f

+ 1 - 1
src/core/instance/render-helpers/bind-object-listeners.js

@@ -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
       }
     }
   }

+ 42 - 1
test/unit/features/directives/on.spec.js

@@ -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
@@ -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>`