国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

Vue框架里使用Swiper的方法示例

2019-11-19 12:53:34
字體:
來源:轉載
供稿:網友

下載swiper

首先使用npm 或者cnpm下載swiper

cnpm install swiper

引入swiper

import Swiper from ‘swiper'; import ‘swiper/dist/css/swiper.min.css';

使用swiper

<div class="swiper-container">  <div class="swiper-wrapper">   <div class="swiper-slide">    <img src="../../static/images/ad1.jpg" alt="">   </div>   <div class="swiper-slide">    <img src="../../static/images/ad2.jpg" alt="">   </div>   <div class="swiper-slide">    <img src="../../static/images/ad3.jpg" alt="">   </div>  </div> </div>

mounted里面調用

  mounted(){    var mySwiper = new Swiper('.swiper-container', {     autoplay:true,     loop:true    })   },

注意

如果想要從后臺請求圖片放上去 new Swiper要寫在網絡請求成功的函數里面,否則不會出來數據。

slider組件的內容如下:

<template> <swiper :options="swiperOption" ref="mySwiper">  <!-- slides -->  <swiper-slide v-for="(picitem,index) in items" :key="index">   <img :src="picitem.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/1.jpg'},     {src: 'http://localhost/static/images/2.jpg'},     {src: 'http://localhost/static/images/3.jpg'},     {src: 'http://localhost/static/images/4.jpg'},     {src: 'http://localhost/static/images/5.jpg'}    ],   }  },  components: {   swiper,   swiperSlider  } }</script><style lang="stylus" rel="sheetstylus"></style>

解釋一下:autoplay:true這樣可以解決不自動輪播問題。如果想設置滾動的時間,用speed設置相應時間即可。direction可以設置輪播的方向。具體的參數可參考swiper的官網地址:http://www.swiper.com.cn/api/Effects/2015/0308/193.html

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 固始县| 喀什市| 香格里拉县| 县级市| 深水埗区| 河北省| 红河县| 万全县| 清原| 长治市| 南阳市| 阳山县| 泰安市| 大余县| 靖江市| 广平县| 合水县| 潮州市| 盱眙县| 南阳市| 江达县| 东港市| 瓮安县| 北安市| 荆门市| 永昌县| 临朐县| 武定县| 晋城| 兴海县| 社旗县| 大安市| 潜山县| 隆化县| 尖扎县| 东乌珠穆沁旗| 广昌县| 黎平县| 宣汉县| 温宿县| 商洛市|