1
0
mirror of https://gitee.com/vant-contrib/vant.git synced 2025-04-06 03:57:59 +08:00
vant/src/composition/use-lazy-render.ts
2020-09-14 20:32:58 +08:00

18 lines
351 B
TypeScript

import { ref, watch, WatchSource, VNode } from 'vue';
export function useLazyRender(show: WatchSource<boolean>) {
const inited = ref(false);
watch(
show,
(value) => {
if (value) {
inited.value = value;
}
},
{ immediate: true }
);
return (render: () => VNode) => () => (inited.value ? render() : null);
}