这里以vant中的轮播图组件为例
<template>
<div id="app">
<van-swipe class="my-swipe" ref="box" @change="changeEvent" :autoplay="3000" indicator-color="white" :vertical="false" :height="200" :stop-propagation="true">
<van-swipe-item v-for="item in 4" @click="clickEvent">{{item}}</van-swipe-item>
</van-swipe>
</div>
</template>
<script>
export default {
methods: {
clickEvent(ev) {
console.log(ev)
},
changeEvent(idx) {
console.log(idx)
}
},
mounted(){
this.$refs.box.swipeTo(2)
}
}
</script>