问题描述: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,入参为当前切换的对象的索引。
如果有错的地方,望指正。