fix: Work 板块动画改用函数 ref 收集卡片
- 根因2:HomePartnersWork 用字符串 ref(ref="cardRefs")收集 v-for 卡片, 在异步 useFetch 数据下数组不可靠填充;改用函数 ref(:ref="el=>setCardRef(el,idx)"), 与 HomeUpdates(正常工作)一致 - 保留数据就绪后再初始化 + inited 幂等
This commit is contained in:
@@ -28,6 +28,11 @@ const workPinRef = ref<HTMLElement | null>(null)
|
|||||||
|
|
||||||
const cardRefs = ref<HTMLElement[]>([])
|
const cardRefs = ref<HTMLElement[]>([])
|
||||||
|
|
||||||
|
// 函数 ref:异步数据下可靠收集卡片 DOM(与 HomeUpdates 一致,字符串 ref 在异步 v-for 下不可靠)
|
||||||
|
const setCardRef = (el: unknown, index: number) => {
|
||||||
|
if (el) cardRefs.value[index] = el as HTMLElement
|
||||||
|
}
|
||||||
|
|
||||||
const partners = [
|
const partners = [
|
||||||
{
|
{
|
||||||
id: 'p1',
|
id: 'p1',
|
||||||
@@ -209,10 +214,10 @@ onUnmounted(() => {
|
|||||||
<div class="relative w-full h-[78svh] md:h-[82svh] lg:h-[88svh] p-[clamp(14px,2.4vw,28px)]">
|
<div class="relative w-full h-[78svh] md:h-[82svh] lg:h-[88svh] p-[clamp(14px,2.4vw,28px)]">
|
||||||
<div class="relative h-full w-full">
|
<div class="relative h-full w-full">
|
||||||
<NuxtLink
|
<NuxtLink
|
||||||
v-for="item in works"
|
v-for="(item, idx) in works"
|
||||||
:key="item.slug"
|
:key="item.slug"
|
||||||
:to="`/work/${item.slug}`"
|
:to="`/work/${item.slug}`"
|
||||||
ref="cardRefs"
|
:ref="(el: unknown) => setCardRef(el, idx)"
|
||||||
class="will-change-transform relative block"
|
class="will-change-transform relative block"
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
|
|||||||
Reference in New Issue
Block a user