vant/packages/mixins/bind-event.js
2019-06-06 11:49:39 +08:00

25 lines
419 B
JavaScript

import { on, off } from '../utils/dom/event';
export function BindEventMixin(handler) {
function bind() {
if (!this.binded) {
handler.call(this, on);
this.binded = true;
}
}
function unbind() {
if (this.binded) {
handler.call(this, off);
this.binded = false;
}
}
return {
mounted: bind,
activated: bind,
destroyed: unbind,
deactivated: unbind
};
}