在vue專案使用swiper@6,解決分頁器pagination不顯示,導航navigation點選不跳轉問題
阿新 • • 發佈:2021-12-24
預設情況下,Swiper 僅匯出核心版本,沒有附加模組(如導航、分頁等)。所以你也需要匯入和配置它們:
import引入之後,初始化swiper,仍需要加入配置。
1 import Swiper, { Navigation, Pagination } from 'swiper'; 2 import 'swiper/swiper-bundle.css'; 3 4 Swiper.use([Navigation, Pagination]); 5 6 export default { 7 mounted() { 8 this.$store.dispatch("getBannerList");9 setTimeout(() => { 10 let mySwiper = new Swiper(".swiper-container", { 11 preventClicks: false, 12 preventClicksPropagation: false, 13 loop: true, 14 pagination: { 15 el: ".swiper-pagination", 16 clickable:true, 17 }, 18 autoplay: true, 19 navigation: { 20 nextEl: ".swiper-button-next", 21 prevEl: ".swiper-button-prev", 22 }, 23 }); 24 }, 2000); 25 }, 26 }
如果要使用所有模組(捆綁包)匯入 Swiper,則應從swiper/bundle
以下位置匯入:
import Swiper from 'swiper/bundle';
詳細情況檢視官網:https://swiperjs.com/get-started