baixingwenzheng-pc/node_modules/vdirs/es/mousemoveoutside.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2024-01-29 09:26:07 +08:00
import { on, off } from 'evtd';
const ctxKey = '@@mmoContext';
const mousemoveoutside = {
mounted(el, { value }) {
el[ctxKey] = {
handler: undefined
};
if (typeof value === 'function') {
el[ctxKey].handler = value;
on('mousemoveoutside', el, value);
}
},
updated(el, { value }) {
const ctx = el[ctxKey];
if (typeof value === 'function') {
if (ctx.handler) {
if (ctx.handler !== value) {
off('mousemoveoutside', el, ctx.handler);
ctx.handler = value;
on('mousemoveoutside', el, value);
}
}
else {
el[ctxKey].handler = value;
on('mousemoveoutside', el, value);
}
}
else {
if (ctx.handler) {
off('mousemoveoutside', el, ctx.handler);
ctx.handler = undefined;
}
}
},
unmounted(el) {
const { handler } = el[ctxKey];
if (handler) {
off('mousemoveoutside', el, handler);
}
el[ctxKey].handler = undefined;
}
};
export default mousemoveoutside;