vue轮播图


// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
Vue.use(VueAwesomeSwiper, /* { default global options } */)
Vue.config.productionTip = false /* eslint-disable no-new */
new Vue({
el: '#app',
router,
components: { App },
template: '<App/>'
})
<template>
<div class="swiper">
<a href="#" :class="currentTab==0?'focus':''" data-current="0" @click="switchTab('点击了slider1',$event)">slider1</a>
<a href="#" :class="currentTab==1?'focus':''" data-current="1" @click="switchTab('点击了slider1',$event)">slider2</a>
<a href="#" :class="currentTab==2?'focus':''" data-current="2" @click="switchTab('点击了slider1',$event)">slider3</a>
<swiper :options="swiperOption" ref="mySwiper" @slideChangeTransitionEnd="moveEnd('滑块移动结束')">
<swiper-slide v-for="(item, index) in slides" :key="index"><img :src="item"></swiper-slide>
</swiper>
</div>
</template>
<script>
import { swiper, swiperSlide } from 'vue-awesome-swiper';
export default{
name: 'test2',
data(){
return {
currentTab: 0,
slides: [
'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511015180050&di=0d2ee92eead284e8133d6df07535d75a&imgtype=0&src=http%3A%2F%2Fimg.sc115.com%2Fuploads1%2Fsc%2Fjpgs%2F1512%2Fapic16988_sc115.com.jpg',
'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511015180167&di=7412fd486c47c15f1d27485be0d7bd28&imgtype=0&src=http%3A%2F%2Fwww.duoxinqi.com%2Fimages%2F2012%2F06%2F20120605_8.jpg',
'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511015180167&di=3bcedd33a30129b9951be2a81f9b505c&imgtype=0&src=http%3A%2F%2Fpic1.5442.com%2F2015%2F0420%2F06%2F05.jpg'
],
//轮播config
swiperOption: {
// 如果自行设计了插件,那么插件的一些配置相关参数,也应该出现在这个对象中,如下debugger
debugger: true,
// autoplay: true,
// loop: true,
slidesPerView: "auto",//设置slider容器能够同时显示的slides数量(carousel模式)。可以设置为数字(可为小数,小数不可loop),或者 'auto'则自动根据slides的宽度来设定数量。loop模式下如果设置为'auto'还需要设置另外一个参数loopedSlides。
centeredSlides: true,//<span style="color:rgb(68,68,68);font-family:'microsoft yahei';font-size:13px;">设定为true时,活动块会居中,而不是默认状态下的居左。</span>
hashNavigation: true,
}
}
},
methods: {
switchTab: function (prompt,res) {
// console.log(prompt,res.target.dataset.current);
this.currentTab = res.target.dataset.current;
this.swiper.slideTo(res.target.dataset.current, 1000, false)
},
moveEnd: function(prompt){
console.log(prompt);
let oIndex = this.swiper.activeIndex;
console.log(oIndex);
this.currentTab = oIndex;
// if(oIndex <= 2) {
// this.currentTab = oIndex;
// } else {
// this.currentTab = oIndex - 3;
// }
}
},
mounted() {
console.log('this is current swiper instance object', this.swiper);
},
components: {
swiper,
swiperSlide
},
computed: {
swiper () {
return this.$refs.mySwiper.swiper
}
}
} </script>
<style scoped>
.swiper {
margin: 10px auto;
width: 10rem;
height: 6.4rem;
/*overflow: hidden;*/
}
.swiper .swiper-slide {
width: 8.53rem;
height: 6.4rem;
}
.swiper-slide.swiper-slide-active img{
margin-top: 0;
width: 100%;
height: 100%;
}
.swiper img {
display: block;
margin: 0 auto;
margin-top: 3.5%;
width: 90.635%;
height: 90.625%;
vertical-align: middle;
-webkit-transition: all .5s ease 0s;
-moz-transition: all .5s ease 0s;
-ms-transition: all .5s ease 0s;
-o-transition: all .5s ease 0s;
transition: all .5s ease 0s;
}
.focus {
color: red;
}
</style>
vue轮播图的更多相关文章
- vue轮播图插件vue-awesome-swiper的使用与组件化
不管是APP还是移动端网页开发,轮播图在大部分项目当中都是存在的,这时候如果用vue开发项目,选择一款好的插件并且封装好是很重要的 1. 推荐使用vue-awesome-swiper 安装:cnpm ...
- Vue轮播图插件---Vue-Awesome-Swiper
轮播图插件 Vue-Awesome-Swiper 地址:https://github.com/surmon-china/vue-awesome-swiper 安装:npm install vue-aw ...
- 做一个vue轮播图组件
根据huangyi老师的慕课网vue项目跟着做的,下面大概记录了下思路 1.轮播图的图 先不做轮播图逻辑部分,先把数据导进来,看看什么效果.在recommend组件新建一个recommends的数组, ...
- vue轮播图插件之vue-awesome-swiper
移动端轮播图插件,在使用iview图形界面插件中的carousel组件无法实现触摸滑动后,转而使用vue-awesome-swiper插件 1.npm安装 npm i vue-awesome-swip ...
- vue --轮播图
轮播图,可以使用mint-ui中的swipe HTML: <Swipe :auto="4000"> <SwipeItem v-for="item in ...
- vue轮播图实现
1.先安装组件 cnpm install vue-awesome-swiper; 2.在main.js下引入文件: import VueAwsomeSwiper from 'vue-awesome-s ...
- vue 轮播图插件 vue-awesome-swiper
1.npm安装 npm install vue-awesome-swiper --save 2.vue 引入 //在main.js 中全局引入 import VueAwesomeSwiper from ...
- vue轮播图中间大两头小
<template> <div v-if="items.length" class="full-page-slide-wrapper"> ...
- vue music-抓取歌单列表数据(渲染轮播图)
下载安装新依赖 babel-runtime:对es6语法进行转译 fastclick:对移动端进行点击300毫秒延迟 ,,取消掉 babel-polyfill:API 先添加,在npm install ...
随机推荐
- Linux 下 YUM 安装 PHP 5.5 (及5.6)
原文链接: http://blog.aboutc.net/linux/50/yum-install-php-on-linux 系统环境: CentOS 6.4 x86_64 Fedora 20 x86 ...
- java 加密解密工具类(实用!!!)
最近发现了一个加密解密的好例子,很方便使用,可以作为平时开发的工具集,记录一下. package com.sh.springboottdemo2.util; import com.sun.org.ap ...
- Spring Boot 之restful风格
步骤一:restful风格是什么? 我们知道在做web开发的过程中,method常用的值是get和post.可事实上,method值还可以是put和delete等等其他值. 既然method值如此丰富 ...
- mysql常见知识点总结
mysql常见知识点总结 参考: http://www.cnblogs.com/hongfei/archive/2012/10/20/2732516.html https://www.cnblogs. ...
- webform button
https://www.codeproject.com/Questions/412553/differences-between-onClick-and-onClientClick OnClick w ...
- LeetCode——Increasing Triplet Subsequence
Question Given an unsorted array return whether an increasing subsequence of length 3 exists or not ...
- Mac下配置Hadoop环境
下载Hadoop(我下载的是2.8.0版本) 点击此处下载 下载后,使用 tar -zxvf tar包名 解压tar包,解压完成后有这样一个文件出现 修改Hadoop的配置文件 需要修改的配置文件在H ...
- [Pytorch]PyTorch使用tensorboardX(转
文章来源: https://zhuanlan.zhihu.com/p/35675109 https://www.aiuai.cn/aifarm646.html 之前用pytorch是手动记录数据做图, ...
- 【Python】“UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9”根因及解决方法
背景 自动化测试调用HTMLTestRunner生成测试报告的时候,出现了编码错误,错误如题 原因 搜索了很多资料,得出的结论是python的str默认是ascii编码,和unicode编码冲突,就会 ...
- Win7 64位安装VS2013无法连接远程数据库
win7 64位安装vs2013后连接远程数据库出现下面的问题:A first chance exception of type 'System.AccessViolationException' o ...