监听事件
var App = Intact.extend({
template: template,
defaults: function() {
return {count: 0};
},
onClick: function(e) {
this.set('count', this.get('count') + 1);
}
});
Intact.mount(App, document.getElementById('appevent'));
利用bind
方法,我们可以往事件处理函数传递参数。
var App = Intact.extend({
template: template,
},
onClick: function(num, e) {
this.set('count', this.get('count') + num);
}
});
Intact.mount(App, document.getElementById('appevent1'));
var App = Intact.extend({
template: template,
onClick: function(e) {
e.preventDefault();
}
});
Intact.mount(App, document.getElementById('appevent2'));
监听组件事件
绑定组件暴露的事件,和原生事件一样,例如:
var Component = Intact.extend({
onClick: function() {
this.trigger('increase');
}
});
var App = Intact.extend({
template: template,
defaults: {
count: 0
},
_init: function() {
this.Component = Component;
},
add: function() {
this.set('count', this.get('count') + 1);
}
});
Intact.mount(App, document.getElementById('appevent3'));
@since v2.2.0 无需
bind(self)
,默认会指向绑定事件的实例