問題描述:vue 使用elementui的Carousel 走馬燈組件,change切換時回調方法的使用?
使用步驟:
代碼:
<template>
<el-carousel indicator-position="outside" @change="handlerChange">
<el-carousel-item v-for="item in 4" :key="item">
<h3>{{ item }}</h3>
</el-carousel-item>
</el-carousel>
</template>
步驟一:在el-carousel標籤上添加 @change="handlerChange“。
代碼:
export default { name: 'HelloWorld',
methods: {
//切換監聽方法
handlerChange(index){
console.log(index);
}
}
}
步驟二:在方法methods上定義handlerChange,入參爲當前切換的對象的索引。
如果有錯的地方,望指正。