Work on export and moving to Vue composition API
This commit is contained in:
parent
b0fae3396d
commit
9a124c5ab9
22 changed files with 660 additions and 906 deletions
39
src/components/messages/composition/useLazyLoad.ts
Normal file
39
src/components/messages/composition/useLazyLoad.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { ComponentInstance, onBeforeUnmount, Ref, ref, ShallowRef, watch } from "vue";
|
||||
import Intersect, { ObserveDirectiveBinding } from "vuetify/directives/intersect";
|
||||
|
||||
export const useLazyLoad = (props: { root: Readonly<ShallowRef<ComponentInstance<any>>> }) => {
|
||||
const isVisible: Ref<boolean> = ref(false);
|
||||
const binding: Ref<ObserveDirectiveBinding | undefined> = ref(undefined);
|
||||
|
||||
watch(
|
||||
props.root,
|
||||
(newval: ComponentInstance<any>) => {
|
||||
if (newval && !binding.value) {
|
||||
const binding: ObserveDirectiveBinding = {
|
||||
modifiers: {
|
||||
once: false,
|
||||
quiet: false,
|
||||
},
|
||||
value(isIntersecting, entries, observer) {
|
||||
isVisible.value = isIntersecting;
|
||||
},
|
||||
instance: newval,
|
||||
oldValue: undefined,
|
||||
dir: {},
|
||||
};
|
||||
Intersect.mounted(newval.$el, binding);
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (binding.value && binding.value.instance) {
|
||||
Intersect.unmounted(binding.value.instance.$el, binding.value);
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
isVisible,
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue