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的更多相关文章

  1. taro 自定义 轮播图组件

    1.代码 components/MySwiper/index.js /** * 轮播图组件 */ import Taro, { Component } from '@tarojs/taro'; imp ...

  2. 微信小程序轮播图组件 swiper,swiper-item及轮播图片自适应

    官网地址:https://developers.weixin.qq.com/miniprogram/dev/component/swiper.html index.wxml文件 indicator-d ...

  3. vue编写轮播图组件

    <template>  <div id="slider">    <div class="window" @mouseover=& ...

  4. reactjs-swiper react轮播图组件基于swiper

    react轮播图组件基于swiper demo地址:http://reactjs-ui.github.io/reactjs-swiper/simple.html 1. 下载安装 npm install ...

  5. vue移动音乐app开发学习(三):轮播图组件的开发

    本系列文章是为了记录学习中的知识点,便于后期自己观看.如果有需要的同学请登录慕课网,找到Vue 2.0 高级实战-开发移动端音乐WebApp进行观看,传送门. 完成后的页面状态以及项目结构如下: 一: ...

  6. Vue实现音乐播放器(七):轮播图组件(二)

    轮播图组件 <template> <div class="slider" ref="slider"> <div class=&qu ...

  7. 【自定义轮播图】微信小程序自定义轮播图无缝滚动

    先试试效果,可以通过设置参数调整样式 微信小程序中的轮播图可以直接使用swiper组件,如下: <swiper indicator-dots="{{indicatorDots}}&qu ...

  8. 原生JS面向对象思想封装轮播图组件

    原生JS面向对象思想封装轮播图组件 在前端页面开发过程中,页面中的轮播图特效很常见,因此我就想封装一个自己的原生JS的轮播图组件.有了这个需求就开始着手准备了,代码当然是以简洁为目标,轮播图的各个功能 ...

  9. Vue2 轮播图组件 slide组件

    Vue2原生始轮播图组件,支持宽度自适应.高度设置.轮播时间设置.左右箭头按钮控制,圆点按钮切换,以及箭头.圆点按钮是否显示. <v-carousel :slideData="slid ...

随机推荐

  1. 实训day02 python

    一.数据类型 列表: 定义:在[]内,可以存放多个任意类型的值,并以逗号隔开: 一般用于存放学生的爱好,课堂的周期等. 定义一个学生列表,可存放多个学生 students = ['A','B','C' ...

  2. 1.入手树莓派之linux环境搭建

    最近刚刚买了一款 树莓派3代B型 raspberrypi 板载蓝牙和WIFI 英国版本,没玩过,觉得很好奇,生怕记性不好哈,把自己玩的过程记录一下,以备不时之需: 需要材料: 1) 树莓派: 2)sd ...

  3. 最短路 || UOJ 19 寻找道路

    UOJ j19 寻找道路 在有向图G中,每条边的长度均为 1,现给定起点和终点,请你在图中找一条从起点到终点的最短路径,该路径满足以下条件: 路径上的所有点的出边所指向的点都直接或间接与终点连通. * ...

  4. python猜年龄游戏升级版

    猜年龄游戏升级版 要求:允许用户最多尝试3次,每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y,就继续让其猜3次,以此往复,如果回答N,就退出程序,如何猜对了,就直接退出 age = 1 ...

  5. 关于Error:Maven Resources Compiler: Maven project configuration required for module '项目名' isn't available. Compilation of Maven projects is supported only&

    总是出现Error:Maven Resources Compiler: Maven project configuration required for module '项目名' isn't avai ...

  6. vue 错误处理

    https://sentry.io/for/vue/ https://cn.vuejs.org/v2/guide/deployment.html#跟踪运行时错误

  7. vue 项目部署

    vue项目部署到PHP项目 入口目录 vue项目打包后, 是一个单文件html 我们只需要把打包后的文件夹放在php项目的public下面 访问 xxx.com/h5/index.html 就可以访问 ...

  8. PHP调用webService WSDL 接口发送邮件

    1.什么是 webService WSDL?  webService WSDL 暴露一些接口给第三方调用,在底层会转化成一个HTTP请求,主要是不同语言之间为了通讯的一个协议,比如发送邮件的系统是用J ...

  9. 阿里云服务器ecs配置之安装mysql

    安装mysql数据库    1.安装工作:        下载 mysql 源安装包             [root@ming ~]# wget http://dev.mysql.com/get/ ...

  10. Couchbase第一印象(架构特性)

    Couchbase第一印象(架构特性) 面向文档 保存的字节流总有一个 DOCUMENT ID(Object_ID) 高并发性,高灵活性,高拓展性,容错性好 面向文档的集群存储系统 每个文档用一个唯一 ...