Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitaf0f69a

Browse files
committed
Merge pull requestvuejs#808 from dgerber/dev
let v-events accept statements
2 parents4b20ad6 +9587d10 commitaf0f69a

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

‎src/directives/events.js‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
var_=require('../util')
22

3-
module.exports={
3+
module.exports={
4+
5+
acceptStatement:true,
46

57
bind:function(){
68
varchild=this.el.__vue__
@@ -11,14 +13,21 @@ module.exports = {
1113
)
1214
return
1315
}
14-
varmethod=this.vm[this.expression]
15-
if(!method){
16+
},
17+
18+
update:function(handler,oldHandler){
19+
if(typeofhandler!=='function'){
1620
_.warn(
17-
'`v-events` cannot find method "'+this.expression+
18-
'" on the parent instance.'
21+
'Directive "v-events:'+this.expression+'" '+
22+
'expects a function value.'
1923
)
24+
return
25+
}
26+
varchild=this.el.__vue__
27+
if(oldHandler){
28+
child.$off(this.arg,oldHandler)
2029
}
21-
child.$on(this.arg,method)
30+
child.$on(this.arg,handler)
2231
}
2332

2433
// when child is destroyed, all events are turned off,

‎test/unit/specs/directives/events_spec.js‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ if (_.inBrowser) {
5959
expect(spy).not.toHaveBeenCalled()
6060
})
6161

62-
it('should warnwhen method not foundonparent',function(){
63-
newVue({
62+
it('should warn onnon-function values',function(){
63+
varvm=newVue({
6464
el:el,
65+
data:{test:123},
6566
template:'<div v-component="test" v-events="test:test"></div>',
6667
components:{
6768
test:{}
@@ -70,5 +71,24 @@ if (_.inBrowser) {
7071
expect(_.warn).toHaveBeenCalled()
7172
})
7273

74+
it('should accept inline statement',function(done){
75+
varvm=newVue({
76+
el:el,
77+
data:{a:1},
78+
template:'<div v-component="test" v-events="test:a++"></div>',
79+
components:{
80+
test:{
81+
compiled:function(){
82+
this.$emit('test')
83+
}
84+
}
85+
}
86+
})
87+
_.nextTick(function(){
88+
expect(vm.a).toBe(2)
89+
done()
90+
})
91+
})
92+
7393
})
7494
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp