UNPKG

press-ui

Version:

简单、易用的跨端组件库,兼容 Vue2 和 Vue3,同时支持 uni-app和普通 Vue 项目

34 lines (29 loc) 584 B
/** * Bind event when mounted or activated */ import { on, off } from '../../common/dom/event'; let uid = 0; export function BindEventMixin(handler) { const key = `binded_${uid}`; uid += 1; function bind() { const that = this; if (!that[key]) { handler.call(that, on, true); that[key] = true; } } function unbind() { const that = this; if (that[key]) { handler.call(that, off, false); that[key] = false; } } return { mounted: bind, activated: bind, deactivated: unbind, beforeDestroy: unbind, }; }