vue 中swiper的使用教程
Install
在vue cli下的使用
npm
install vue-awesome-swiper --save
在main.js中
import VueAwesomeSwiper from 'vue-awesome-swiper' import 'swiper/dist/css/swiper.css' Vue.use(VueAwesomeSwiper)
在component.vue中
<template> <div id="container"> <swiper :options="swiperOption" ref="mySwiper"> <swiper-slide class="swiper-slide games"> <img src="/src/assets/LB/LB_07.jpg" alt=""> </swiper-slide> <swiper-slide class="swiper-slide games"> <img src="/src/assets/LB/LB_06.jpg" alt=""> </swiper-slide> <swiper-slide class="swiper-slide games"> <img src="/src/assets/LB/LB_05.jpg" alt=""> </swiper-slide> <swiper-slide class="swiper-slide games"> <img src="/src/assets/LB/LB_04.jpg" alt=""> </swiper-slide> <div class="swiper-pagination" slot="pagination"></div> <div class="swiper-button-prev" slot="button-prev"></div> <div class="swiper-button-next" slot="button-next"></div> </swiper> </div> </template> <script> import { swiper, swiperSlide } from 'vue-awesome-swiper' export default { name: 'carrousel', data () { return { swiperOption: { autoplay : { disableOnInteraction: false, //用戶操作后是否禁止自動(dòng)循環(huán) delay: 3000 //自自動(dòng)循環(huán)時(shí)間 }, //可選選項(xiàng),自動(dòng)滑動(dòng) speed: 2000, //切換速度,即slider自動(dòng)滑動(dòng)開始到結(jié)束的時(shí)間(單位ms) loop:true, //循環(huán)切換 grabCursor: true, //設(shè)置為true時(shí),鼠標(biāo)覆蓋Swiper時(shí)指針會(huì)變成手掌形狀,拖動(dòng)時(shí)指針會(huì)變成抓手形狀 // setWrapperSize: true, //Swiper使用flexbox布局(display: flex),開啟這個(gè)設(shè)定會(huì)在Wrapper上添加等于slides相加的寬或高,在對(duì)flexbox布局的支持不是很好的瀏覽器中可能需要用到。 autoHeight: true, //自動(dòng)高度。設(shè)置為true時(shí),wrapper和container會(huì)隨著當(dāng)前slide的高度而發(fā)生變化。 scrollbar: '.swiper-scrollbar', mousewheelControl: true, //設(shè)置為true時(shí),能使用鼠標(biāo)滾輪控制slide滑動(dòng) observeParents: true, //當(dāng)改變swiper的樣式(例如隱藏/顯示)或者修改swiper的子元素時(shí),自動(dòng)初始化swiper pagination: { el: '.swiper-pagination', // type : 'progressbar', //分頁器形狀 clickable :true, //點(diǎn)擊分頁器的指示點(diǎn)分頁器會(huì)控制Swiper切換 }, navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, }, computed: { swiper() { return this.$refs.mySwiper.swiper } } } } } </script> <style scoped> img { width: 100%; height: auto; } </style>
參考:https://github.com/surmon-china/vue-awesome-swiper
https://surmon-china.github.io/vue-awesome-swiper/
總結(jié)
以上所述是小編給大家介紹的vue 中swiper的使用教程,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
vue3的介紹和兩種創(chuàng)建方式詳解(cli和vite)
這篇文章主要介紹了vue3的介紹和兩種創(chuàng)建方式(cli和vite),vue3對(duì)比vue2帶來的性能提升有很多優(yōu)勢(shì),總體來說Vue 3在性能、開發(fā)體驗(yàn)和代碼組織方面都有所改進(jìn),使得它更加適合于大型、復(fù)雜的應(yīng)用程序開發(fā),需要的朋友可以參考下2023-04-04Vue中watch與watchEffect的區(qū)別詳細(xì)解讀
這篇文章主要介紹了Vue中watch與watchEffect的區(qū)別詳細(xì)解讀,watch函數(shù)與watchEffect函數(shù)都是監(jiān)聽器,在寫法和用法上有一定區(qū)別,是同一功能的兩種不同形態(tài),底層都是一樣的,需要的朋友可以參考下2023-11-11vue 路由懶加載中給 Webpack Chunks 命名的方法
這篇文章主要介紹了在 vue 路由懶加載中給 Webpack Chunks 命名的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04vue3源碼剖析之簡(jiǎn)單實(shí)現(xiàn)方法
源碼的重要性相信不用再多說什么了吧,特別是用Vue 框架的,一般在面試的時(shí)候面試官多多少少都會(huì)考察源碼層面的內(nèi)容,下面這篇文章主要給大家介紹了關(guān)于vue3源碼剖析之簡(jiǎn)單實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2021-09-09element-ui使用導(dǎo)航欄跳轉(zhuǎn)路由的用法詳解
今天小編就為大家分享一篇element-ui使用導(dǎo)航欄跳轉(zhuǎn)路由的用法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-08-08vue3按鈕點(diǎn)擊頻率控制的實(shí)現(xiàn)示例
在前端開發(fā)中,當(dāng)用戶頻繁連續(xù)點(diǎn)擊按鈕,可能會(huì)導(dǎo)致頻繁的請(qǐng)求或者觸發(fā)過多的操作,本文主要介紹了vue3按鈕點(diǎn)擊頻率控制的實(shí)現(xiàn)示例,感興趣的可以了解一下2024-01-01webpack+vue中使用別名路徑引用靜態(tài)圖片地址
這篇文章主要介紹了webpack+vue中使用別名路徑引用靜態(tài)圖片地址,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11