after-leave
在元素上绑定after-leave事件,并在t+100ms后立即执行一遍此事件
clickoutside
点击元素外面才会触发的事件 zhuanlan.zhihu.com/p/63520317 实现方式 无法提前获得元素的外面是哪个元素.但这些元素一定是在document中
// 在document上绑定mousedown, mouseup, 其中 callback放在mouseup中
!Vue.prototype.$isServer && on(document, 'mousedown', e => (startClick = e));
// nodeList中存放了所有使用了v-clickoutside的元素
!Vue.prototype.$isServer && on(document, 'mouseup', e => {
// 逐个触发
nodeList.forEach(node => node[ctx].documentHandler(e, startClick));
});
//documentHandler(e, startClick)
// 入参是 mouseup事件和 mousedonw 事件
// vnode 是绑定元素的 vnode el是绑定的元素
function(mouseup = {}, mousedown = {}) {
if (!vnode ||
!vnode.context ||
!mouseup.target ||
!mousedown.target ||
el.contains(mouseup.target) || //点击的不能是当前元素
el.contains(mousedown.target) ||
el === mouseup.target ||
(vnode.context.popperElm &&
(vnode.context.popperElm.contains(mouseup.target) ||
vnode.context.popperElm.contains(mousedown.target)))) return;
if (binding.expression &&
el[ctx].methodName &&
vnode.context[el[ctx].methodName]) {
vnode.context[el[ctx].methodName]();
} else {
el[ctx].bindingFn && el[ctx].bindingFn();
}
}
import Clickoutside from 'element-ui/src/utils/clickoutside';
directives: { Clickoutside },
v-clickoutside="close"
resize-event
import { addResizeListener, removeResizeListener } from 'element-ui/src/utils/resize-event';
mounted() {
this.updateItems();
this.$nextTick(() => {
addResizeListener(this.$el, this.resetItemPosition);
if (this.initialIndex < this.items.length && this.initialIndex >= 0) {
this.activeIndex = this.initialIndex;
}
this.startTimer();
});
},
beforeDestroy() {
if (this.$el) removeResizeListener(this.$el, this.resetItemPosition);
this.pauseTimer();
}