mirror of
https://github.com/youzan/vant.git
synced 2025-10-21 03:11:15 +00:00
[improvement] add bind event mixin
This commit is contained in:
24
packages/mixins/bind-event.js
Normal file
24
packages/mixins/bind-event.js
Normal file
@@ -0,0 +1,24 @@
|
||||
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
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user