primevue
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primevue) [ • 1.05 kB
JavaScript
import e from"primevue/basecomponent";import{openBlock as t,createElementBlock as o,mergeProps as n,renderSlot as i,createCommentVNode as r}from"vue";var d={name:"DeferredContent",extends:e,emits:["load"],data:()=>({loaded:!1}),mounted(){this.loaded||(this.shouldLoad()?this.load():this.bindScrollListener())},beforeUnmount(){this.unbindScrollListener()},methods:{bindScrollListener(){this.documentScrollListener=()=>{this.shouldLoad()&&(this.load(),this.unbindScrollListener())},window.addEventListener("scroll",this.documentScrollListener)},unbindScrollListener(){this.documentScrollListener&&(window.removeEventListener("scroll",this.documentScrollListener),this.documentScrollListener=null)},shouldLoad(){if(this.loaded)return!1;{const e=this.$refs.container.getBoundingClientRect();return document.documentElement.clientHeight>=e.top}},load(e){this.loaded=!0,this.$emit("load",e)}}};d.render=function(e,d,l,s,c,u){return t(),o("div",n({ref:"container"},e.ptm("root")),[c.loaded?i(e.$slots,"default",{key:0}):r("",!0)],16)};export{d as default};