最后寫vue項目用到swiper,一開始只引入swiper,沒引入vue-awesome-swiper一直報錯,后來才發現有vue專用的vue-awesome-swiper,
組合npm指令:npm install swiper vue-awesome-swiper --save
然而,百度獲取回調的activeIndex方法很多是這樣的:
此時需要把click改為slideChangeTransitionEnd,將變量swiper打印的時候顯示undefined!為什么呢?
當嘗試打印this.$refs.mySwiper的時候發現:
這可能才是我想要的屬性,修改后:
切屏成功打印!
結果代碼:
on:{
slideChangeTransitionEnd:()=>{
let swiper = this.$refs.mySwiper.$swiper;
let activeIndex = swiper.activeIndex;
console.log(activeIndex)
},
}