vue-swiper的使用教程
作者:流浪_光头 时间:2024-04-27 16:17:56
swiper是我之前做前端页面会用到的一个插件,我自己认为是非常好用的。swiper提供了形式多种多样、适应各个终端的轮播图效果。本文是小编给大家带来的vue-swiper的使用教程。
vue-awesome-swiper官网链接https://www.npmjs.com/package/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版本,所以并没有什么样式上的问题,今天我更新了包试了一下之前写的,发现样式上出问题了。所以才去找的文档,在此补充,希望能帮到各位
来源:https://www.cnblogs.com/maomao93/p/6830626.html
标签:vue,swiper


猜你喜欢
图片完美缩放
2024-04-22 13:07:22
Pycharm-community-2020.2.3 社区版安装教程图文详解
2022-07-02 06:30:00

获取python文件扩展名和文件名方法
2023-06-24 16:51:24
Python实现堆排序的方法详解
2023-12-02 07:43:20

go语言beego框架web开发语法笔记示例
2024-05-21 10:25:22
opera img onload重复执行
2008-01-17 12:01:00
关于MySql链接url参数的设置
2024-01-19 17:45:14
Python入门之三角函数sin()函数实例详解
2021-11-09 18:31:21
Python嵌套循环的使用
2022-11-12 17:19:23

Python装饰器decorator用法实例
2023-02-06 23:26:43
python实现套接字创建
2021-09-09 05:12:04
MySQL的存储引擎InnoDB和MyISAM
2024-01-26 02:19:30

document.createElement()用法及注意事项
2008-04-21 15:16:00
几个你不知道的技巧助你写出更优雅的vue.js代码
2024-05-13 09:14:39

解决vue单页面多个组件嵌套监听浏览器窗口变化问题
2024-04-27 15:48:29

JDBC 连接MySQL实例详解
2024-01-26 23:34:27
numpy系列之数组重塑的实现
2022-10-20 13:36:35
Python实现淘宝秒杀功能的示例代码
2021-05-26 09:41:49

详解Vue-cli webpack移动端自动化构建rem问题
2024-04-29 13:40:06
详解Python3迁移接口变化采坑记
2022-12-25 14:29:49