Skip to content

Commit 3a5bf4d

Browse files
committed
Update VPSwiper
1 parent aee3cad commit 3a5bf4d

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

.vitepress/theme/components/VPSwiper.vue

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,12 @@ const props = defineProps({
1313
numberOfSlides: { type: Number, required: true },
1414
altTextPrefix: { type: String, default: 'Loading' },
1515
fileExt: { type: String, default: 'jpg' },
16+
padStart: { type: Number, default: 1 },
1617
height: { type: String, default: '496px' },
1718
18-
padStart: { type: Number, default: 1 },
1919
slidesPerView: { type: Number, default: 1 },
20-
breakpoints: {
21-
type: Object,
22-
default() {
23-
return {}
24-
},
25-
},
26-
pagination: {
27-
type: Object,
28-
default() {
29-
return {}
30-
},
31-
},
20+
breakpoints: { type: Object, default: () => ({}) },
21+
pagination: { type: Object, default: () => ({}) },
3222
lazyPreloadPrevNext: { type: Number, default: 2 },
3323
buttonText: { type: String, default: 'View in Fullscreen' },
3424
keyboard: { type: Boolean, default: true },
@@ -37,14 +27,15 @@ const props = defineProps({
3727
grabCursor: { type: Boolean, default: true },
3828
loop: { type: Boolean, default: true },
3929
effect: { type: String, default: '' },
40-
coverflowEffect: {
41-
type: Object,
42-
default() {
43-
return { slideShadows: false }
44-
},
45-
},
30+
coverflowEffect: { type: Object, default: () => ({ slideShadows: false }) },
4631
})
4732
33+
const baseUrl = props.baseUrl.replace(/\/$/, '')
34+
const getImageSource = (index) => {
35+
const fileName = String(index).padStart(props.padStart, '0')
36+
return `${baseUrl}/${fileName}.${props.fileExt}`
37+
}
38+
4839
const swiperEl = ref(null)
4940
const requestFullscreen = () => {
5041
// noinspection JSUnresolvedReference
@@ -120,11 +111,7 @@ const requestFullscreen = () => {
120111
:coverflow-effect="props.coverflowEffect"
121112
>
122113
<SwiperSlide v-for="i in props.numberOfSlides" :key="i">
123-
<img
124-
:src="`${props.baseUrl}/${String(i).padStart(props.padStart, '0')}.${props.fileExt}`"
125-
:alt="`${props.altTextPrefix} ${i}`"
126-
loading="lazy"
127-
/>
114+
<img :src="getImageSource(i)" :alt="`${props.altTextPrefix} ${i}`" loading="lazy" />
128115
</SwiperSlide>
129116
</Swiper>
130117
</ClientOnly>

0 commit comments

Comments
 (0)