Просмотр исходного кода

Merge pull request #1949 from rhyzx/inline-statement-variable

Add $arguments variable in component events inline statement #1945
Evan You 10 лет назад
Родитель
Сommit
f819514e0e
2 измененных файлов с 21 добавлено и 1 удалено
  1. 3 1
      src/instance/api/data.js
  2. 18 0
      test/unit/specs/instance/events_spec.js

+ 3 - 1
src/instance/api/data.js

@@ -1,5 +1,5 @@
 import Watcher from '../../watcher'
-import { del } from '../../util/index'
+import { del, toArray } from '../../util/index'
 import { parseText } from '../../parsers/text'
 import { parseDirective } from '../../parsers/directive'
 import { getPath } from '../../parsers/path'
@@ -23,7 +23,9 @@ export default function (Vue) {
       if (asStatement && !isSimplePath(exp)) {
         var self = this
         return function statementHandler () {
+          self.$arguments = toArray(arguments)
           res.get.call(self, self)
+          self.$arguments = null
         }
       } else {
         try {

+ 18 - 0
test/unit/specs/instance/events_spec.js

@@ -237,6 +237,24 @@ describe('Instance Events', function () {
       expect(vm.a).toBe(1)
     })
 
+    it('passing $arguments', function () {
+      new Vue({
+        el: document.createElement('div'),
+        template: '<comp @ready="onReady($arguments[1])"></comp>',
+        methods: {
+          onReady: spy
+        },
+        components: {
+          comp: {
+            compiled: function () {
+              this.$emit('ready', 123, 1234)
+            }
+          }
+        }
+      })
+      expect(spy).toHaveBeenCalledWith(1234)
+    })
+
     describe('attached/detached', function () {
 
       it('in DOM', function () {