当前位置: 移动技术网 > IT编程>脚本编程>vue.js > vue-swiper的使用教程

vue-swiper的使用教程

2018年09月21日  | 移动技术网IT编程  | 我要评论

罗永浩手机,自我介绍ppt,陈歌华

swiper是我之前做前端页面会用到的一个插件,我自己认为是非常好用的。swiper提供了形式多种多样、适应各个终端的轮播图效果。本文是小编给大家带来的vue-swiper的使用教程。

vue-awesome-swiper官网链接

和上一篇随笔一样,我们先下载包,然后去main.js里面配置。

npm install vue-awesome-swiper --save

  我们可以用import的方法

// import 
import vue from 'vue'
import vueawesomeswiper from 'vue-awesome-swiper' 

  也可以用require

var vue = require('vue')
var vueawesomeswiper = require('vue-awesome-swiper') 

  两者都可以达到目的,然后再mian.js里面全局注册

vue.use(vueawesomeswiper) 

  在模板里使用

import { swiper, swiperslide } from 'vue-awesome-swiper'
export default {
 components: {
  swiper,
  swiperslide
 }
} 

<template>
 <swiper :options="swiperoption" ref="myswiper">
  <!-- slides -->
  <swiper-slide>i'm slide 1</swiper-slide>
  <swiper-slide>i'm slide 2</swiper-slide>
  <swiper-slide>i'm slide 3</swiper-slide>
  <swiper-slide>i'm slide 4</swiper-slide>
  <swiper-slide>i'm slide 5</swiper-slide>
  <swiper-slide>i'm slide 6</swiper-slide>
  <swiper-slide>i'm slide 7</swiper-slide>
  <!-- optional controls -->
  <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>
  <div class="swiper-scrollbar"  slot="scrollbar"></div>
 </swiper>
</template>

<script>
 // swiper options example:
 export default {
  name: 'carrousel',
  data() {
   return {
    swiperoption: {//以下配置不懂的,可以去swiper官网看api,链接http://www.swiper.com.cn/api/
     // notnexttick是一个组件自有属性,如果notnexttick设置为true,组件则不会通过nexttick来实例化swiper,也就意味着你可以在第一时间获取到swiper对象,<br>        假如你需要刚加载遍使用获取swiper对象来做什么事,那么这个属性一定要是true
     notnexttick: true,
     // swiper configs 所有的配置同swiper官方api配置
     autoplay: 3000,
     direction : 'vertical',
     grabcursor : true,
     setwrappersize :true,
     autoheight: true,
     pagination : '.swiper-pagination',
     paginationclickable :true,
     prevbutton:'.swiper-button-prev',//上一张
     nextbutton:'.swiper-button-next',//下一张
     scrollbar:'.swiper-scrollbar',//滚动条
     mousewheelcontrol : true,
     observeparents:true,
     // 如果自行设计了插件,那么插件的一些配置相关参数,也应该出现在这个对象中,如下debugger
     debugger: true,
    }
   }
  },
 }
</script> 

  这样就可以使用啦

<-----------------------补充时间2017/9/22 21:00------------------------>

 

平时没怎么用这个插件,今天看了下,发现有点小小的改动,可能导致之前的受到影响,npm包发布者的原话是

// starting with version 2.6.0, you need to manually introduce swiper's css这句话的意思是:从版本2.6.0开始,您需要手动引入swiper的css

require('swiper/dist/css/swiper.css')

我写这篇随笔的时候,还是2.4.2版本,还没有更新到2.6.0版本,所以并没有什么样式上的问题,今天我更新了包试了一下之前写的,发现样式上出问题了。所以才去找的文档,在此补充,希望能帮到各位

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网