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浏览器上遇到的显示问题探索
		前言: 最近项目有一个需求,想要下图效果,鼠标指向头像图片,图片会放大同时上面的轮播会跟着切换: 鼠标移开头像图片,图片变回原来的大小 注:下图是我根据上面需求已经实现的效果,所以截图方便说明 思考: ... 
随机推荐
- 创建Idea创建SpringBoot项目 - 各个目录的解释
			[SpringBoot-创建项目]一.通过Idea创建SpringBoot项目 一.首先我们通过Idea创建一个新项目 二.选择sdk和快速构建模板 三.填写项目基本信息 三.选择项目依赖 四.填写项 ... 
- Mysql 中需不需要commit
			摘自:https://blog.csdn.net/zzyly1/article/details/81003122 mysql在进行增删改操作的时候需不需要commit,这得看你的存储引擎, 如果是不支 ... 
- spark 笔记 10:  TaskScheduler相关
			任务调度器的接口类.应用程序可以定制自己的调度器来执行.当前spark只实现了一个任务调度器) )))))val createTime = System.currentTimeMillis()clas ... 
- Dubbo Configuration
			可配置参数 http://dubbo.apache.org/zh-cn/docs/user/references/xml/introduction.html 与 spring 整合的几种方式 Spri ... 
- 4.数据挖掘的数据仓库与OLAP技术
			1.什么是数据仓库 面向主题的.集成的.时变的.非易失的 2.数据仓库和异种DBMS 3.OLTP vs OLAP 4.为什么建立分离的数据仓库? 5.多维数据模型(数据仓库的概念建模)三类度量 4. ... 
- C++抽象类实践
			实践如下: #include <iostream> using namespace std; class Service { public: // 有一个虚函数即为抽象类 int id; ... 
- Origin 2017 给曲线加标记符号
			最近在用Origin 2017画曲线图,需要给图像得曲线加上不同得标记符号用以区分,把操作步骤记录下来,免得忘了. 1.用Origin 2017打开一个曲线图,在任意一条曲线上点击右键弹出菜单,选择[ ... 
- hive跑mapreduce报java.lang.RuntimeException: Error in configuring object
			写于2016.7月 最近项目需要在hbase上做统计分析,在本机上装了hive,结果跑小批量数据sum时报错: hive> select count(*) from page_view; Tot ... 
- apache访问日志
			#错误日志ErrorLog "logs/dummy-host2.example.com-error_log" #访问日志CustomLog "logs/dummy-hos ... 
- nmon报告指标含义
			nmon分析文件详细指标详解指标类型指标名称指标含义SYS_SUMMCPU%cpu占有率变化情况:IO/secIO的变化情况:AAAAIXAIX版本号:buildbuild版本号:command执行命 ... 
