1- import { reactive , computed , watch , defineComponent } from 'vue'
1+ import { reactive , computed , watch , defineComponent , Fragment } from 'vue'
22import PlaceholderWithoutTracking from './PlaceholderWithoutTracking.tsx'
33import isIntersectionObserverAvailable from '../utils/intersection-observer' ;
44import PlaceholderWithTracking from './PlaceholderWithTracking.tsx'
@@ -18,7 +18,9 @@ import PlaceholderWithTracking from './PlaceholderWithTracking.tsx'
1818// threshold: number
1919// }
2020export default defineComponent ( {
21+ compatConfig : { MODE : 3 } ,
2122 name : 'LazyLoadComponent' ,
23+ inheritAttrs : false ,
2224 props : {
2325 afterLoad : {
2426 type : Function ,
@@ -72,9 +74,8 @@ export default defineComponent({
7274 type : Object ,
7375 default : ( ) => { }
7476 }
75-
7677 } ,
77- setup ( props , { slots, attrs } ) {
78+ setup ( props , { slots } ) {
7879 const state = reactive ( {
7980 visible : props . visibleByDefault ?? false ,
8081 loaded : false ,
@@ -98,7 +99,6 @@ export default defineComponent({
9899 )
99100
100101 const onVisible = ( ) => {
101- if ( state . loaded ) return
102102 state . loaded = true
103103 state . visible = true
104104 props . afterLoad ?.( )
@@ -108,37 +108,31 @@ export default defineComponent({
108108 props . afterLoad ?.( )
109109 props . afterLoad ?.( )
110110 }
111-
112111 return ( ) => {
112+ if ( state . visible ) {
113+ return slots . default ?.( )
114+ }
113115 return isScrollTracked ||
114116 ( props . useIntersectionObserver && isIntersectionObserverAvailable ( ) ) ?
115- < >
116- < PlaceholderWithoutTracking
117- height = { props . height }
118- onVisible = { onVisible }
119- // placeholder={props.placeholder}
120- scrollPosition = { props . scrollPosition }
121- threshold = { props . threshold }
122- useIntersectionObserver = { props . useIntersectionObserver }
123- width = { props . width }
124- >
125- { slots . default ?.( ) }
126- </ PlaceholderWithoutTracking >
127- </ >
117+ < PlaceholderWithoutTracking
118+ height = { props . height }
119+ onVisible = { onVisible }
120+ placeholder = { props . placeholder }
121+ scrollPosition = { props . scrollPosition }
122+ threshold = { props . threshold }
123+ useIntersectionObserver = { props . useIntersectionObserver }
124+ width = { props . width }
125+ />
128126 :
129- < >
130- < PlaceholderWithTracking
131- height = { props . height }
132- onVisible = { onVisible }
133- // placeholder={props.placeholder}
134- scrollPosition = { props . scrollPosition }
135- threshold = { props . threshold }
136- useIntersectionObserver = { props . useIntersectionObserver }
137- width = { props . width }
138- >
139- { slots . default ?.( ) }
140- </ PlaceholderWithTracking >
141- </ >
127+ < PlaceholderWithTracking
128+ height = { props . height }
129+ onVisible = { onVisible }
130+ placeholder = { props . placeholder }
131+ scrollPosition = { props . scrollPosition }
132+ threshold = { props . threshold }
133+ useIntersectionObserver = { props . useIntersectionObserver }
134+ width = { props . width }
135+ />
142136 }
143137 }
144138} )
0 commit comments