vue自定义轮播图组件 swiper
1.banner 组件
components/Banner.vue
<!-- 轮播图 组件 -->
<template>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" v-for="str in listImg" :style="{ backgroundImage: 'url(' + str.img + ')' }"></div>
</div>
<div class="swiper-pagination swiper-pagination-bullets"></div>
</div>
</template> <script>
// npm install swiper --save
import Swiper from 'swiper';
import 'swiper/dist/css/swiper.min.css'; export default {
props: ['listImg'],
name: 'banner',
mounted() {
let mySwiper = new Swiper('.swiper-container', {
pagination: { // 按钮
el: '.swiper-pagination',
clickable :true, // 分页导航是否可点击
},
loop: true, // 环路(无缝滚动)
speed: 600, // 切换速度
autoplay: { // 自动切换
delay: 3000, // 自动切换的时间间隔
stopOnLastSlide: false, // 如果设置为true,当切换到最后一个slide时停止自动切换(loop模式下无效)
disableOnInteraction: false, // 用户操作swiper之后,是否禁止autoplay.默认为true:停止
}
});
}
}
</script> <style lang="less" scoped>
.swiper-container {
width: 100%;
height: 200px;
.swiper-wrapper {
width: 100%;
height: 100%;
}
.swiper-slide {
background-position: center;
background-size: cover;
width: 100%;
height: 100%;
img {
width: 100%;
height: 100%;
}
}
}
</style>
2.swiper 组件
components/Swiper.vue
<template>
<div class="swiper-container">
<div class="swiper-wrapper">
<div class="swiper-slide" v-for="item in swiper"><img :src="item.img" alt=""></div>
</div>
<div class="swiper-pagination swiper-pagination-bullets"></div>
</div>
</template>
<script>
// npm install swiper --save
import Swiper from 'swiper';
import 'swiper/dist/css/swiper.min.css'; export default {
name: 'swiper',
data() {
return {
mySwiper: null
}
},
props: ['swiper'], //swiper的就是test这个数据传递来的
methods: {
_initSwiper() {
this.mySwiper = new Swiper('.swiper-container', {
pagination: { // 按钮
el: '.swiper-pagination',
clickable :true, // 分页导航是否可点击
},
loop: true, // 环路(无缝滚动)
speed: 600, // 切换速度
autoplay: { // 自动切换
delay: 3000, // 自动切换的时间间隔
stopOnLastSlide: false, // 如果设置为true,当切换到最后一个slide时停止自动切换(loop模式下无效)
disableOnInteraction: false, // 用户操作swiper之后,是否禁止autoplay.默认为true:停止
}
})
},
_updateSwiper() {
this.$nextTick(() => {
this.mySwiper.update(true); //swiper update的方法
})
},
swiperUpdate() {
if (this.mySwiper) { //节点存在
this._updateSwiper(); //更新
} else {
this._initSwiper(); //创建
}
}
},
watch: {
//通过props传来的数据 和 组件一加载节点就创建成功 二者不是同步,实时监听的swiper(传递的值)的变化
swiper() {
this.swiperUpdate();
}
},
mounted() {
this.swiperUpdate(); //页面一加载拉去数据创建节点
}
}
</script> <style lang="less" scoped>
.swiper-container {
width: 100%;
height: 200px;
margin-top: 10px;
.swiper-wrapper {
width: 100%;
height: 100%;
.swiper-slide {
background-size: cover;
width: 100%;
height: 200px;
img {
width: 100%;
height: 100%;
}
}
}
}
</style>
3.页面调用
<!-- 书影音 -->
<template>
<div>
<!-- 标题栏 -->
<mt-header title="书影音"></mt-header>
<!-- 轮播图 组件一 -->
<banner :listImg="bannerList"></banner>
<!-- 轮播图 组件二 -->
<swiper :swiper="bannerList"></swiper>
</div>
</template> <script>
import Banner from '../components/Banner.vue'
import Swiper from '../components/Swiper.vue' export default {
name: 'AudioBook',
components: {
Banner,
Swiper
},
data(){
return {
bannerList: [
{"type":"1","img":"http://www.youdingsoft.com/fileUploadsmall/20180119172411843341.jpg;","url":""},
{"type":"1","img":"http://www.youdingsoft.com/fileUploadsmall/20180119172434968049.jpg;","url":""},
{"type":"1","img":"http://www.youdingsoft.com/fileUploadsmall/20180119172503906167.jpg;","url":""},
{"type":"1","img":"http://www.youdingsoft.com/fileUploadsmall/20180119172518390352.jpg;","url":""},
{"type":"1","img":"http://www.youdingsoft.com/fileUploadsmall/20180119172540250495.jpg;","url":""},
{"type":"1","img":"http://www.youdingsoft.com/fileUploadsmall/20180119172552359735.jpg;","url":""}
]
}
}
}
</script> <style lang="less" scoped>
//
</style>
4.效果图
vue自定义轮播图组件 swiper的更多相关文章
- taro 自定义 轮播图组件
1.代码 components/MySwiper/index.js /** * 轮播图组件 */ import Taro, { Component } from '@tarojs/taro'; imp ...
- 微信小程序轮播图组件 swiper,swiper-item及轮播图片自适应
官网地址:https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html index.wxml文件 indicator-d ...
- vue编写轮播图组件
<template> <div id="slider"> <div class="window" @mouseover=& ...
- reactjs-swiper react轮播图组件基于swiper
react轮播图组件基于swiper demo地址:http://reactjs-ui.github.io/reactjs-swiper/simple.html 1. 下载安装 npm install ...
- vue移动音乐app开发学习(三):轮播图组件的开发
本系列文章是为了记录学习中的知识点,便于后期自己观看.如果有需要的同学请登录慕课网,找到Vue 2.0 高级实战-开发移动端音乐WebApp进行观看,传送门. 完成后的页面状态以及项目结构如下: 一: ...
- Vue实现音乐播放器(七):轮播图组件(二)
轮播图组件 <template> <div class="slider" ref="slider"> <div class=&qu ...
- 【自定义轮播图】微信小程序自定义轮播图无缝滚动
先试试效果,可以通过设置参数调整样式 微信小程序中的轮播图可以直接使用swiper组件,如下: <swiper indicator-dots="{{indicatorDots}}&qu ...
- 原生JS面向对象思想封装轮播图组件
原生JS面向对象思想封装轮播图组件 在前端页面开发过程中,页面中的轮播图特效很常见,因此我就想封装一个自己的原生JS的轮播图组件.有了这个需求就开始着手准备了,代码当然是以简洁为目标,轮播图的各个功能 ...
- Vue2 轮播图组件 slide组件
Vue2原生始轮播图组件,支持宽度自适应.高度设置.轮播时间设置.左右箭头按钮控制,圆点按钮切换,以及箭头.圆点按钮是否显示. <v-carousel :slideData="slid ...
随机推荐
- 普通用户切换到root用户
普通用户切换到root用户首先按组合键 CTRL+ALT+T 进入终端界面,一般终端界面默认为普通用户权限模式,如何从普通用户进入root用户首先重置root密码输入 sudo passwd root ...
- zay大爷的膜你题 D2T1 江城唱晚
依旧是外链... 这一次网易云爆炸了....所以我决定后面的都用QQ 下面是题面 这道题是一道傻逼题 数学题,我们仔细看一看,首先有m朵花的话,我们就有m!种排列方式(也就是m的全排列), 然后我们假 ...
- pm2 start命令进阶详解
在node的世界里面,并不存在nginx或者apache,甚至tomcat这种东东.一个node,本身就用几行代码,就可以启动个server进程,监听个端口,为大家提供web服务.这和传统的网站代码的 ...
- VS打开文件,解决方案资源管理器自动定位到文件位置
打开 工具-->选项-->项目和解决方案-->常规,勾选“在解决方案资源管理器中跟踪活动项”
- ios operationqueue
http://www.hrchen.com/2013/06/multi-threading-programming-of-ios-part-2/
- IO之Object流举例
import java.io.*; public class TestObjectIO { public static void main(String args[]) throws Exceptio ...
- Linux 命令学习(1): head和tail
版权声明:本文为博主原创文章,未经允许,不得转载. head head 命令可以将一段文本的开头一部分输出到标准输出. head命令既可以处理文本文件也可以处理标准输入. 基本应用 处理文本文件: h ...
- Linux中的FTP服务
FTP服务 文件传输协议 FTPFile Transfer Protocol 早期的三个应用级协议之一 基于C/S结构 双通道协议:数据和命令连接 数据传输格式:二进制(默认)和文本 两种模式:服务器 ...
- JS 获取字符串中的url并返回其下标索引
//获取字符串中的url极其下标索引 function getHttpUrlArray(s) { var s1 = s.match(/http.*/); if(s1 == null) { return ...
- win10修改文件管理器默认打开我的电脑