5

Looking at the element ui marquee document, it is found that there is only the chang event, not the mouse click event
image.png


Under the code transformation, add a variable to distinguish whether it is triggered by clicking or triggered by automatic rotation

View demo

html

<el-carousel :interval="3000" arrow="always" trigger='click' @change='swiperchange' @mouseenter.native="isclick = true" @mouseleave.native="isclick = false">
      <el-carousel-item v-for="item in 4" :key="item">
        <h3>{{ item }}</h3>
      </el-carousel-item>
    </el-carousel>

js

  data() {
    return {
      isclick: false,
    };
  },
  methods: {
    swiperchange(n,o) {
      if(this.isclick){
       console.log('我是点击触发的'+n)
      }
    }
  }

WX20210922-091703.png


雾岛听风
12.1k 声望8.6k 粉丝

丰富自己,胜过取悦别人。