v3+ts手写轮播图
父组件传入需要的数据,是否自动播放(autoPlay)和间隔时间(:duration="3000")
子组件用defineProps接收
<script lang="ts" setup name="XtxCarousel">
import { BannerItem } from '@/type/data';
import { onMounted, onUnmounted, PropType, ref } from 'vue';
const {slides,autoPlay,duration} = defineProps({
slides:{
//as是断言 PropType是类型 BannerItem是我们之前拿到的数据的类型
// BannerItem = {
//hrefUrl: string;
//id: string;
//imgUrl: string;
//type: string;
// }
type:Array as PropType<BannerItem[]>
},
//是否自动播放
autoPlay:{
type:Boolean,
default:false
},
//间隔的时间