如何用vue制作轮播图片的效果
Admin 2022-08-06 群英技术资讯 726 次浏览
今天小编跟大家讲解下有关“如何用vue制作轮播图片的效果”的内容 ,相信小伙伴们对这个话题应该有所关注吧,小编也收集到了相关资料,希望小伙伴们看了有所帮助。本文实例为大家分享了vue实现轮播图片的具体代码,供大家参考,具体内容如下
1、效果图

2、案例
<template>
<section class="body">
<section class="wrap">
<swiper :options="swiperOption" class="swiper-wrap" ref="mySwiper" v-if="banner.length!=0">
<swiper-slide v-for="(item,index) in banner" :key="index" >
//点击图片跳到哪里,这里跳到home页面 item举例:{img:http://www.***.com/home/images/index_img02.png,url:/home}
<img :src="item.img" alt="" @click="skip_out_page(item.url)" />
</swiper-slide>
<!-- 常见的小圆点 -->
<div class="swiper-pagination" v-for="(item,index) in banner" :key="index" slot="pagination" ></div>
</swiper>
</section>
</section>
</template>
<script>
export default {
data() {
const that = this;
return {
imgIndex: 1,
swiperOption: {
//是一个组件自有属性,如果notNextTick设置为true,组件则不会通过NextTick来实例化swiper,也就意味着你可以在第一时间获取到swiper对象,假如你需要刚加载遍使用获取swiper对象来做什么事,那么这个属性一定要是true
notNextTick: true,
//循环,而不是每次都突然回到第一个
loop: true,
//设定初始化时slide的索引,加载页面时显示的第几个,从0开始
initialSlide: 0,
//自动播放
autoplay: {
/*切换轮播图片的时间,即上次切换成功后到再次需要切换的时间*/
delay: 1500,
stopOnLastSlide: false,
/* 触摸滑动后是否继续轮播 false触摸后不再点击继续轮播,true触摸后不再点击不轮播,停在最后一次页面*/
disableOnInteraction: false
},
//滑动速度,时间单位,越小越快,与上面 delay 区别,speed是完成切换所需时间,delay是切换成功后停留多长时间再切换
speed: 800,
//滑动方向
direction: "horizontal",
//小手掌抓取滑动
grabCursor: true,
on: {
//滑动之后回调函数
slideChangeTransitionStart: function() {
/* realIndex为滚动到当前的slide索引值 */
that.imgIndex= this.realIndex - 1;
},
},
//分页器设置
pagination: {
el: ".swiper-pagination",
clickable: true,
type: "bullets"
}
},
banner: []
}
},
methods: {
skip_out_page(v) {
window.location.href = v
},
get_data() {
this.$http.get('test').then(res => {
if(res.data.code == '0000'){
this.banner = res.data.img_info
}
});
}
},
mounted() {
this.get_data()
}
}
</script>
<style lang="scss">
.swiper-wrap{
width: 100%;
height: 210px;
background-color: #fff;
}
.swiper-pagination{
background: #fff;
}
.swiper-pagination-bullet{
background: #ccc;
width: 10px;
height: 10px;
opacity: 1;
}
.swiper-pagination-bullet-active{
background: #00C293;
}
</style>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
目录文件如 httpFile.js如下:consthttpd=require("http");constfs=require("fs");//创建服务httpd.createServer((req,res)=>{//读取www文件夹下的路径fs.readFile(`www${req.url}`,(err,data)=>{
本篇文章给大家带来了关于javascript的相关知识,其中详细介绍了javaScript三种引入方式行内式,嵌入样式、外部样式及其使用方式;下面一起来看一下,希望对大家有帮助。
在jquery中,可以利用length属性来查询有几个数组元素,length属性可以统计数组元素的个数并返回,语法为“数组元素对象.length”。
vuex数据持久化实现有什么方法?对于vue数据持久化的问题,下面小编通过实例来给大家分享一下实现方法,有vuex-persistedstate和vuex-persist这两种方法,下面我们来详细了解一下。
最近接触了vue.js,一度非常好奇vue.js是如何监测数据更新并且重新渲染页面,这篇文章主要给大家介绍了关于Vue源码学习之响应式是如何实现的相关资料,需要的朋友可以参考下
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008