mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
25 lines
415 B
JavaScript
25 lines
415 B
JavaScript
import { on, off } from '../utils/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
|
|
};
|
|
}
|