From f83ed29fc3988a7ef2720f2fd7a5d229797efb75 Mon Sep 17 00:00:00 2001 From: xpyjs Date: Mon, 1 Jul 2024 14:54:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E8=BF=9E=E7=BA=BF?= =?UTF-8?q?=E7=9A=84=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/composables/useLinks.ts | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/composables/useLinks.ts b/src/composables/useLinks.ts index 1db1d5f..02c4540 100644 --- a/src/composables/useLinks.ts +++ b/src/composables/useLinks.ts @@ -1,19 +1,33 @@ import type RowItem from '@/models/data/row'; import { useStore } from '@/store'; import { type LinkProps } from '@/typings/link'; -import { isBoolean } from 'lodash'; -import { type Ref, watchEffect } from 'vue'; +import { debounce, isBoolean } from 'lodash'; +import { type Ref, watch } from 'vue'; +import useInView from './useInView'; export default () => { - const { linking, $links, $data } = useStore(); + const { linking, $links } = useStore(); + const { inView } = useInView(); function initLinks(links: Ref) { - $links.init($data.flatData, links.value); + $links.init(inView, links.value); - watchEffect(() => { - // 更新数据 - $links.update($data.flatData, links.value); - }); + const debouncedUpdate = debounce($inView => { + $links.update($inView, links.value); + }, 100); + + watch( + () => inView, + () => { + // 更新数据 + + debouncedUpdate(inView); + }, + { + immediate: true, + deep: true + } + ); } function setLinking(params: {