This commit is contained in:
lcw
2025-11-22 21:59:58 +08:00
parent ea3022c3f6
commit 93c49dff27
661 changed files with 195357 additions and 2160 deletions

View File

@ -0,0 +1,34 @@
import {
getScrollContainer
} from "element-plus/lib/utils";
/**
* 自定义懒加载指令
*/
export default {
name:'InfiniteScroll',
inserted(el,binding,vnode){
//绑定回调函数
const cb = binding.value;
//当前组件实例引用
const vm = vnode.context;
const container = getScrollContainer(el,true);
const {delay,immediate} =getScrollOptions(el,vm);
const onScroll = throttle(delay,handleScroll.bind(el,cb));
el[scope] = {el,vm,container ,onScroll};
if(container){
container.addEventListener('scroll',onScroll);
if(immediate){
const observer = el[scope].observer = new MutationObserver(onScroll);
observer.observe(container,{childList:true,subtree:true});
onScroll()
}
}
},
unbind(el){
const {container,onScroll} = el[scope];
if(container){
container.removeEventListener('scrrll',onScroll)
}
}
}