Files
shoot-miniprograms/src/components/Swiper.vue

96 lines
1.6 KiB
Vue
Raw Normal View History

2025-05-10 16:57:36 +08:00
<script setup>
import { ref } from "vue";
const props = defineProps({
interval: {
type: Number,
default: 3000,
},
autoplay: {
type: Boolean,
default: false,
},
data: {
type: Array,
default: () => [],
},
2025-07-12 16:07:07 +08:00
onChange: {
type: Function,
default: (index) => {},
},
2025-05-10 16:57:36 +08:00
});
const currentIndex = ref(0);
const handleChange = (e) => {
currentIndex.value = e.detail.current;
2025-07-12 16:07:07 +08:00
props.onChange(e.detail.current);
2025-05-10 16:57:36 +08:00
};
</script>
<template>
<view>
<swiper
class="swiper-container"
v-if="data.length > 0"
:current="currentIndex"
@change="handleChange"
:autoplay="autoplay"
:interval="interval"
>
<swiper-item v-for="(imgSrc, index) in data" :key="index">
<image :src="imgSrc" mode="widthFix" />
</swiper-item>
</swiper>
<view class="dots">
<view
v-for="index in data.length"
:key="index"
class="dot"
:class="{ active: currentIndex === index - 1 }"
/>
</view>
</view>
</template>
<style scoped>
.swiper-container {
2025-06-22 15:04:10 +08:00
width: 100%;
height: 570px;
2025-05-10 16:57:36 +08:00
position: relative;
2025-05-15 12:43:40 +08:00
border-radius: 10px;
overflow: hidden;
2025-05-10 16:57:36 +08:00
}
.swiper-container > swiper {
width: 100%;
height: 100%;
}
.swiper-container image {
2025-06-22 15:04:10 +08:00
width: calc(100% - 20px);
2025-07-10 15:34:00 +08:00
margin: 0 10px;
border-radius: 10px;
2025-05-10 16:57:36 +08:00
}
.dots {
position: absolute;
2025-08-04 18:36:44 +08:00
bottom: 15%;
2025-05-10 16:57:36 +08:00
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 8px;
}
.dot {
width: 8px;
height: 8px;
border-radius: 50%;
2025-07-12 16:07:07 +08:00
background-color: #ccc;
2025-05-10 16:57:36 +08:00
}
.dot.active {
2025-07-12 16:07:07 +08:00
background-color: #000;
2025-05-10 16:57:36 +08:00
}
</style>