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 ...
随机推荐
- hibernate5.x版本org.hibernate.MappingException: Unknown entity问题
/* * //创建hibernate配置对象 Configuration cfg = new Configuration(); cfg.configure("hibernate.cfg.xm ...
- 深入理解typeof操作符
typeof可以检测数据的类型 typeof返回结果的其实是字符串:可以通过以下测试出来 console.log( typeof(typeof(a))); // string typeof返回的数据类 ...
- Android Studio修改默认字体大小
安装Android Studio后,默认的字体很小,看着很不舒服,如下图 因此,我们需要改变字体大小,步骤如下: 一.打开设置 二.找到Font,这里系统的主题不能修改,我们点击Save As... ...
- Saving James Bond - Hard Version
07-图5 Saving James Bond - Hard Version(30 分) This time let us consider the situation in the movie &q ...
- django1.11 启动错误:Generator expression must be parenthesized
错误信息: Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0 ...
- win7 如何将python加入环境变量
我的电脑->右键属性->高级->系统变量 path里加上安装路径,比如 ";C:\Python26;" 请加分号附在其他path后面而不是直接覆盖.
- Leetcode 235.二叉搜索树的公共祖先
二叉搜索树的公共祖先 给定一个二叉搜索树, 找到该树中两个指定节点的最近公共祖先. 百度百科中最近公共祖先的定义为:"对于有根树 T 的两个结点 p.q,最近公共祖先表示为一个结点 x,满足 ...
- zoj 2772 Quick Change
Quick Change Time Limit: 2 Seconds Memory Limit: 65536 KB J.P. Flathead's Grocery Store hires c ...
- php引入PHPMailer发送邮件
昨天做了一个发送邮件的功能,如果直接用mail()函数,需要拥有自己的邮件服务器,所有引入PHPMailer类方便快捷,简单写一下开发步骤: 一.拥有自己的邮箱账号(作为发件人邮箱) 分两种情况: 1 ...
- 79. could not initialize proxy - no Session 【从零开始学Spring Boot】
[原创文章,转载请注明出处] Spring与JPA结合时,如何解决懒加载no session or session was closed!!! 实际上Spring Boot是默认是打开支持sessio ...