1
1
<script lang="ts">
2
- // shared data across instances so we load only once
3
- let data = $ref <SponsorData >()
4
- const base = ` https://sponsors.vuejs.org `
5
- </script >
6
-
7
- <script setup lang="ts">
8
- import { onMounted , onUnmounted } from ' vue'
9
-
10
2
interface Sponsor {
11
3
url: string
12
4
img: string
@@ -22,6 +14,16 @@ interface SponsorData {
22
14
bronze: Sponsor []
23
15
}
24
16
17
+ // shared data across instances so we load only once
18
+ let data = $ref <SponsorData >()
19
+ let pending = false
20
+
21
+ const base = ` https://sponsors.vuejs.org `
22
+ </script >
23
+
24
+ <script setup lang="ts">
25
+ import { onMounted , onUnmounted } from ' vue'
26
+
25
27
const { tier, placement = ' aside' } = defineProps <{
26
28
tier: keyof SponsorData
27
29
placement? : ' aside' | ' page' | ' landing'
@@ -32,17 +34,21 @@ let visible = $ref(false)
32
34
33
35
onMounted (async () => {
34
36
// only render when entering view
35
- const observer = new IntersectionObserver ((entries ) => {
36
- if (entries [0 ].isIntersecting ) {
37
- visible = true
38
- observer .disconnect ()
39
- }
40
- }, { rootMargin: ' 0px 0px 300px 0px' })
37
+ const observer = new IntersectionObserver (
38
+ (entries ) => {
39
+ if (entries [0 ].isIntersecting ) {
40
+ visible = true
41
+ observer .disconnect ()
42
+ }
43
+ },
44
+ { rootMargin: ' 0px 0px 300px 0px' }
45
+ )
41
46
observer .observe (container )
42
47
onUnmounted (() => observer .disconnect ())
43
48
44
49
// load data
45
- if (! data ) {
50
+ if (! pending ) {
51
+ pending = true
46
52
data = await (await fetch (` ${base }/data.json ` )).json ()
47
53
}
48
54
})
@@ -76,7 +82,8 @@ onMounted(async () => {
76
82
v-if =" placement !== 'page' && tier !== 'special'"
77
83
href =" /sponsor/"
78
84
class =" sponsor-item action"
79
- >Your logo</a >
85
+ >Your logo</a
86
+ >
80
87
</div >
81
88
</template >
82
89
0 commit comments