vue-awesome-swiper轮播插件
1. github上搜索vue-awesome-swiper
2. readme中有安装方法,建议在插件名后@版本号,使用稳定的老版本 npm install vue-awesome-swiper@x.x.x --save
3. 在项目main.js中引入
import Vue from 'vue'
import VueAwesomeSwiper from 'vue-awesome-swiper' // require styles
import 'swiper/dist/css/swiper.css' Vue.use(VueAwesomeSwiper, /* { default global options } */)
4.创建单文件组件Swiper.vue(单文件组件三部分template、script、style)
<template>
<swiper :options="swiperOption">
<!-- slides -->
//这里是轮播的内容
<swiper-slide>I'm Slide 1</swiper-slide>
<swiper-slide>I'm Slide 2</swiper-slide>
<swiper-slide>
<img src=""/>
</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>
export default {
name: 'HomeSwiper',
// 子组件的data必须是个函数
data() {
return {
swiperOption: {}
}
},
}
</script> <style lang="stylus" scoped> </style>
5. 在别的页面中引用,如在Home.vue
<template>
<div>
<home-header></home-header>
<home-swiper></home-swiper>
</div>
</template> <script>
import HomeHeader from './component/Header'
import HomeSwiper from './component/Swiper'
export default {
name: 'Home',
components: {
HomeHeader,
HomeSwiper
} }
</script> <style lang="stylus"> </style>
6.防抖动:在网速不好的情况下,swiper未加载出前,下方的div会占据,等到swiper出来时,占据位置的div会蹦走
处理方法:swiper外层嵌套div,让这个div撑开高度
<template>
<div class="wrapper">
<swiper :options="swiperOption">
...
</swiper>
</div>
</template> <script>
...
</script> <style lang="stylus" scoped>
.wrapper
overflow: hidden
width:100%
height:0
padding-bottom: 31.25% (宽高比,如果写在height,那么是和父级元素的高度,不是对比wrapper的宽度)
</style>
7.轮播图下面跟着跑的一排小圆点
<template>
<div class="wrapper">
<swiper :options="swiperOption">
<!-- 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>
</div>
</template> <script>
export default {
name: 'HomeSwiper',
// 子组件的data必须是个函数
data() {
return {
swiperOption: {
pagination: 'swiper-pagination'
}
}
},
}
</script> <style lang="stylus" scoped>
//三个箭头是穿透,这样就突破了scoped的限制
//这个class名从何而来,是从页面中审查元素得到的
.wrapper >>> .swiper-pagination-bullet-active
background: red !important
.wrapper
overflow: hidden
width:100%
height:0
padding-bottom: 31.25% (宽高比,如果写在height,那么是和父级元素的高度,不是对比wrapper的宽度)
</style>
8.Vue是数据驱动的框架,轮播的图片地址和数量不该固定写死
处理方法:v-for循环item,注意循环要加key
<template>
<div class="wrapper">
<swiper :options="swiperOption">
<!-- slides -->
<swiper-slide v-for="item of swiperList" :key="item.id">
<img :src="item.imgUrl" />
</swiper-slide>
<!-- Optional controls -->
<div class="swiper-pagination" slot="pagination"></div>
</swiper>
</div>
</template> <script>
export default {
name: 'HomeSwiper',
// 子组件的data必须是个函数
data() {
return {
swiperOption: {
pagination: 'swiper-pagination'
},
swiperList: [{ id: '0001', imgUrl: 'http://lkadand.adoaidiajd.jada.jpg' }, { id: '0002', imgUrl: 'jndakm.adkand.sda.jpg' }]
}
},
}
</script> <style lang="stylus" scoped>
//三个箭头是穿透,这样就突破了scoped的限制
//这个class名从何而来,是从页面中审查元素得到的
.wrapper >>> .swiper-pagination-bullet-active
background: red !important
.wrapper
overflow: hidden
width:100%
height:0
padding-bottom: 31.25% (宽高比,如果写在height,那么是和父级元素的高度,不是对比wrapper的宽度)
</style>
9.循环轮播
处理方法:加loop值为true
<template>
<div class="wrapper">
<swiper :options="swiperOption">
<!-- slides -->
<swiper-slide v-for="item of swiperList" :key="item.id"><img :src="item.imgUrl" /></swiper-slide>
<!-- Optional controls -->
<div class="swiper-pagination" slot="pagination"></div>
</swiper>
</div>
</template> <script>
export default {
name: 'HomeSwiper',
// 子组件的data必须是个函数
data() {
return {
swiperOption: {
pagination: 'swiper-pagination',
loop: true
},
swiperList: [{ id: '0001', imgUrl: 'http://lkadand.adoaidiajd.jada.jpg' }, { id: '0002', imgUrl: 'jndakm.adkand.sda.jpg' }]
}
},
}
</script> <style lang="stylus" scoped>
//三个箭头是穿透,这样就突破了scoped的限制
//这个class名从何而来,是从页面中审查元素得到的
.wrapper >>> .swiper-pagination-bullet-active
background: red !important
.wrapper
overflow: hidden
width:100%
height:0
padding-bottom: 31.25% (宽高比,如果写在height,那么是和父级元素的高度,不是对比wrapper的宽度)
</style>
vue-awesome-swiper轮播插件的更多相关文章
- 使用Swiper轮播插件引起的探索
提到Swiper轮播插件,小伙伴们应该不会感到陌生.以前我主要在移动端上使用,PC端使用较少. 注:这里需要注意的是,在PC端和移动端使用Swiper是不同的 官方给的版本有三个,分别是Swiper2 ...
- vue中引用swiper轮播插件
有时候我们需要在vue中使用轮播组件,如果是在vue组件中引入第三方组件的话,最好通过npm安装,从而进行统一安装包管理. 申明:本文所使用的是vue.2x版本. 通过npm安装插件: npm ins ...
- Swiper轮播插件使用
前文 Swiper是纯javascript打造的滑动特效插件,面向手机.平板电脑等移动终端,能实现触屏焦点图.触屏Tab切换.触屏多图切换等常用效果. 归根到此,Swi ...
- Swiper 轮播插件 之 动态加载无法滑动
1.原因:轮播图未完全动态加载完成,即初始化 2.方法一:ajax链式编程 $.ajax({ type: "get", url: serviceURL + "/listB ...
- vue中添加swiper轮播插件
网上找了很多,最后还是官网最完整. https://github.com/surmon-china/vue-awesome-swiper 安装: 1.npm install vue-awesome-s ...
- 使用swiper 轮播插件ajax 请求加载图片时,无法滑动问题
因为图片是动态创建的,在插件开始初始化时,文档流中没用图片,故没有创建相应宽度.通过调整js加载顺序,问题还是没有解决. 最后找到swiper插件 api 有属性是可以根据内容变动,自动初始化插件的, ...
- Sweetalert模态对话框与Swiper轮播插件、Bootstrap样式组件、AdminLTE后台管理模板地址
Sweetalert纯JS模态对话框插件地址:http://mishengqiang.com/sweetalert/ AdminLTE后台管理模板系统地址(基于Bootstrap):https://a ...
- 【swiper轮播插件】解决swiper轮播插件触控屏问题
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- swiper轮播问题之一:轮播图内容为动态数据生成时轮播图无法自动轮播
本人在用H5做移动端项目中使用Swiper遇到的两个问题,因此加深了对Swiper的掌握,分享出来对刚开始接触Swiper的童鞋们或多或少会有帮助. 首先,new Swiper的初始化最 ...
- swiper轮播在ie浏览器上遇到的显示问题探索
前言: 最近项目有一个需求,想要下图效果,鼠标指向头像图片,图片会放大同时上面的轮播会跟着切换: 鼠标移开头像图片,图片变回原来的大小 注:下图是我根据上面需求已经实现的效果,所以截图方便说明 思考: ...
随机推荐
- JavaBean,EJB,POJO,Spring Bean 的演进历程
JavaBean Sun公司对类提出的规范:1,类是public的2,有一个无参构造方法3,属性修饰要用private,通过get set操作4,实现Serializable接口5,对事件使用Swin ...
- JSTL标签语言
******概述: JSTL是apache对EL表达式的扩展(也就是说JSTL依赖EL),JSTL是标签语言! JSTL标签使用以来非常方便,它与JSP动作标签一定,只不过它不是JSP内置的标签,需要 ...
- leetcode-easy-array-136. Single Number
mycode 75.80% class Solution(object): def singleNumber(self, nums): """ :type nums: ...
- Oracle非分区索引,全局分区索引和本地分区索引。
1.如果按照索引是否分区作为划分依据,Oracle 的索引类型可以分为非分区索引,全局分区索引和本地分区索引. 2.创建演示实例 --创建非分区表create table test_partition ...
- Activity 怎么和 Service 绑定,怎么在 Activity 中启动自己对应的 Service?
Activity 通过 bindService(Intent service, ServiceConnection conn, int flags)跟 Service 进行绑定,当绑定成功的时候 Se ...
- Tensorflow所遇坑
TensorFlow问题: 1.FLAGS._parse_flags()报错AttributeError:_parse_flags 解决: 因为TensorFlow的版本问题了,TensorFlow版 ...
- windows触摸板速度调整
Windows 触摸板滚动速度调整: 在注册表中: The magic key is: Computer\HKEY_CURRENT_USER\Software\Microsoft\Wisp\Tou ...
- PHP加速器eAccelerator安装
程序说明 eAccelerator是一个自由开放源码php加速器,优化和动态内容缓存,提高了php脚本的缓存性能,使得PHP脚本在编译的状态下,对 服务器的开销几乎为零. 它还有对脚本起优化作用,以加 ...
- 如何修改eclipse中的maven的仓库地址
最近的有一个朋友问我如何修改eclipse的maven的本地仓库,我想了一下,这个玩意一般是不用修改的,主要是你本地安装的maven在哪个位置,一般的本地仓库位置在 C:\Users\username ...
- Java编程思想—八皇后问题(数组法、堆栈法)
Java编程思想-八皇后问题(数组法.堆栈法) 实验题目:回溯法实验(八皇后问题) 实验目的: 实验要求: 实验内容: (1)问题描述 (2)实验步骤: 数组法: 堆栈法: 算法伪代码: 实验结果: ...