diff --git a/src/compiler/codegen/events.js b/src/compiler/codegen/events.js index fc817c03d52..f95ea10a4a8 100644 --- a/src/compiler/codegen/events.js +++ b/src/compiler/codegen/events.js @@ -42,6 +42,7 @@ const genGuard = condition => `if(${condition})return null;` const modifierCode: { [key: string]: string } = { stop: '$event.stopPropagation();', prevent: '$event.preventDefault();', + emit: '$emit(arguments.callee.name, ...arguments)', self: genGuard(`$event.target !== $event.currentTarget`), ctrl: genGuard(`!$event.ctrlKey`), shift: genGuard(`!$event.shiftKey`), diff --git a/test/unit/features/directives/on.spec.js b/test/unit/features/directives/on.spec.js index b7801a82f22..1abdbbacbb9 100644 --- a/test/unit/features/directives/on.spec.js +++ b/test/unit/features/directives/on.spec.js @@ -102,6 +102,28 @@ describe('Directive v-on', () => { expect(spy).toHaveBeenCalledWith(true) }) + it('should support the .emit event modifier', () => { + vm = new Vue({ + el, + template: '', + methods: { foo: spy }, + components: { + bar: { + template: '', + components: { + emitter: { + template: '
', + mounted() { + this.$emit('custom', 'a', 'b') + } + } + } + } + } + }) + expect(spy).toHaveBeenCalledWith('a', 'b') + }) + it('should support capture', () => { const callOrder = [] vm = new Vue({