Download swiper
First use npm or cnpm to download swiper
cnpm install swiper
Introduce swiper
import Swiper from ‘swiper'; import ‘swiper/dist/css/';
Using swiper
<div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide"> <img src="../../static/images/" alt=""> </div> <div class="swiper-slide"> <img src="../../static/images/" alt=""> </div> <div class="swiper-slide"> <img src="../../static/images/" alt=""> </div> </div> </div>
Called in mounted
mounted(){ var mySwiper = new Swiper('.swiper-container', { autoplay:true, loop:true }) },
Notice
If you want to put the image requested from the background, new Swiper should be written in the function that has successfully requested the network, otherwise the data will not be released.
The contents of the slider component are as follows:
<template> <swiper :options="swiperOption" ref="mySwiper"> <!-- slides --> <swiper-slide v-for="(picitem,index) in items" :key="index"> <img :src="" alt=""> </swiper-slide> </swiper> </template> <script type="text/ecmascript-6"> import {swiper, swiperSlider} from 'vue-awesome-swiper' export default { data() { return { swiperOption: { notNextTick: true, loop: true, autoplay: true, speed: 1000, direction: 'horizontal', grabCursor: true, setWrapperSize: true, autoHeight: true, pagination: '.swiper-pagination', paginationClickable: true, mousewheelControl: true, observeParents: true, debugger: true }, items: [ {src: 'http://localhost/static/images/'}, {src: 'http://localhost/static/images/'}, {src: 'http://localhost/static/images/'}, {src: 'http://localhost/static/images/'}, {src: 'http://localhost/static/images/'} ], } }, components: { swiper, swiperSlider } } </script> <style lang="stylus" rel="sheetstylus"> </style>
Explain: autoplay:true can solve the problem of not automatically carouseling. If you want to set the scrolling time, just use speed to set the corresponding time. Direction can set the direction of the carousel. For specific parameters, please refer to the official website address of swiper:/api/Effects/2015/0308/
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.