問題概覽:
有一個小型單頁應用項目,嫌用組件式調用vue-swiper麻煩,因此以CDN的方式調用swiper,結果輪播的圖不動了!
爬了半天百度和谷歌都無解決方案,最后曲線救國的方式解決了問題。
解決方法:
在創建swiper時為其設置一個定時器即可解決問題!
bottleLineMove = () => { setTimeout(() => { this.bottleSwiperOne = new Swiper('#bottleLineOne', { loop: true, slidesPerView: 4, spaceBetween: 10, // centeredSlides: true, autoplay: { delay: 2000, disableOnInteraction: false, }, }) this.bottleSwiperTwo = new Swiper('#bottleLineTwo', { loop: true, slidesPerView: 4, spaceBetween: 10, // freeMode: true, autoplay: { delay: 2000, disableOnInteraction: false, }, }) }, 10) }
最后,嘻嘻!