效果

1:在单独文件中使用

  <!-- Top --><swiper ref="mySwiper" :options="swiperOption" class="gallery-top"><swiper-slide class="swiper-slide1" v-for="(item, index) in ListPic" :key="index"><div style="display: flex; align-items: center; justify-content: center; width: 100%; height: 450px"><img style="max-width: 100%; max-height: 100%" :src="item" /></div></swiper-slide><!-- 分页器 --><!-- <div class="swiper-pagination" slot="pagination"></div> --><!-- 左右箭头 --><div class="swiper-button-prev" slot="button-prev"></div><div class="swiper-button-next" slot="button-next"></div></swiper><!-- Bottom --><swiper ref="mySwiper2" :options="swiperOption2" class="gallery-thumbs"><swiper-slide class="swiper-slide2" v-for="(item, index) in ListPic" :key="index"><el-image style="width: 50px; height: 50px" :src="item" fit="cover"></el-image></swiper-slide></swiper>
   //走马灯//topswiperOption: {//显示分页pagination: {el: '.swiper-pagination',clickable: true,watchSlidesVisibility: true, //避免出现bug具体干啥咱也不清楚只能跟着写上去},//设置点击箭头navigation: {nextEl: '.swiper-button-next',prevEl: '.swiper-button-prev',hideOnClick: true,},//开启循环模式// loop: true, //自动循环//speed: 5000, //自动播放 一秒滑动一次},//bottomswiperOption2: {spaceBetween: 10,centeredSlides: true, //true 为居中slideToClickedSlide: true,slidesPerView: 'auto',touchRatio: 0.2,},

放在点击事件里面调用 加载图片的时候调用

this.$nextTick(() => {const mySwiper = this.$refs.mySwiper.$swiper; //topconst mySwiper2 = this.$refs.mySwiper2.$swiper;mySwiper.controller.control = mySwiper2;mySwiper2.controller.control = mySwiper;});

样式

/* 走马灯 */
.swiper-slide2 {margin: 15px 0 0 0;
}
.swiper-slide2:hover {cursor: pointer;
}
.swiper-slide {background-size: cover;background-position: center;
}
.gallery-top {height: 80% !important;width: 100%;
}
.gallery-thumbs {height: 20% !important;box-sizing: border-box;padding: 10px 0;
}
.gallery-thumbs .swiper-slide {width: 7%;height: 100%;opacity: 0.4;
}
.gallery-thumbs .swiper-slide-active {opacity: 1;
}

2:放在组件中使用


Swiper.vue

<template><div><div @click="show = true"><slot></slot></div><el-dialog title="查看图片" :visible.sync="show" width="700px" :close-on-click-modal="false"><!-- Top --><swiper ref="mySwiper" :options="swiperOption" class="gallery-top"><swiper-slide class="swiper-slide1" v-for="(item, index) in list" :key="index"><div style="display: flex; align-items: center; justify-content: center; width: 100%; height: 450px"><img style="max-width: 100%; max-height: 100%" :src="item" /></div></swiper-slide><div class="swiper-button-prev" slot="button-prev"></div><div class="swiper-button-next" slot="button-next"></div></swiper><!-- Bottom 分页器--><swiper ref="mySwiper2" :options="swiperOption2" class="gallery-thumbs"><swiper-slide class="swiper-slide2" v-for="(item, index) in list" :key="index"><el-image style="width: 50px; height: 50px" :src="item" fit="cover"></el-image></swiper-slide></swiper></el-dialog></div>
</template>
<script>
export default {name: 'Preview',props: {list: {type: Array,defalut: () => [],},},data() {return {show: false,//topswiperOption: {//显示分页pagination: {el: '.swiper-pagination',clickable: true,watchSlidesVisibility: true, //避免出现bug具体干啥咱也不清楚只能跟着写上去},//设置点击箭头navigation: {nextEl: '.swiper-button-next',prevEl: '.swiper-button-prev',hideOnClick: true,},//开启循环模式// loop: true, //自动循环//speed: 5000, //自动播放 一秒滑动一次},//bottomswiperOption2: {spaceBetween: 10,centeredSlides: true, //true 为居中slideToClickedSlide: true,slidesPerView: 'auto',touchRatio: 0.2,},};},watch: { //很重要!!!这里仔细看吧 你会明白的show(value) {if (value) {this.$nextTick(() => {const mySwiper = this.$refs.mySwiper.$swiper; //topconst mySwiper2 = this.$refs.mySwiper2.$swiper;console.log(mySwiper);console.log(mySwiper2);mySwiper.controller.control = mySwiper2;mySwiper2.controller.control = mySwiper;});}},},methods: {},mounted() {// console.log(this.show);// if (this.show) {//   this.$nextTick(() => {//     const mySwiper = this.$refs.mySwiper.$swiper; //top//     const mySwiper2 = this.$refs.mySwiper2.$swiper;//     console.log(mySwiper);//     console.log(mySwiper2);//     mySwiper.controller.control = mySwiper2;//     mySwiper2.controller.control = mySwiper;//   });// }},
};
</script><style lang="scss" scoped>
/* 走马灯 */
.swiper-slide2 {margin: 15px 0 0 0;
}
.swiper-slide2:hover {cursor: pointer;
}
.swiper-slide {background-size: cover;background-position: center;
}
.gallery-top {height: 80% !important;width: 100%;
}
.gallery-thumbs {height: 20% !important;box-sizing: border-box;padding: 10px 0;
}
.gallery-thumbs .swiper-slide {width: 7%;height: 100%;opacity: 0.4;
}
.gallery-thumbs .swiper-slide-active {opacity: 1;
}
</style>

使用

//HTML
<ux-table-column title="图片" field="pic" width="150" align="center"><template scope="scope"><!-- photoList 是数组 --><preview :list="scope.row.photoList"><el-button type="primary" size="mini" :disabled="!scope.row.pic && !scope.row.attachedPic">查看</el-button></preview></template>
</ux-table-column>
//js
import Preview from '@/components/Swiper/Swiper';
export default{components: {Preview,},
}

vue使用siwper走马灯相关推荐

  1. vue element-ui 中走马灯自适应图片高度

    图片自适应 废话不多说先上完整的代码 <template><div>{{img_height | add_px}}<el-carousel indicator-posit ...

  2. element走马灯自动_[转]vue Element UI走马灯组件重写

    1.element ui走马灯组件 -- carousel 分析一波源代码: carousel/src/main.vue 文件为 el-carousel文件主要功能 carousel/src/item ...

  3. vue css实现走马灯(轮播)组件,websocket推送数据

    需求 背景:数据统计常需要实现内容定向移动的走马灯效果,便于用户实时观察数据变动. 目标:实现一个vue组件,可以上下左右实现走马灯效果,且走马灯元素可自定义. 技术选型 比较常用的方式是如下几种 j ...

  4. Vue ElementUI el-carousel 走马灯 指示灯样式修改

    Carousel 走马灯 一.原始样式 二.修改后 三.代码 <template><div><el-carousel height="250px" & ...

  5. vue element ui 走马灯轮播图(简单几句话实现自动缩放效果)

    实现效果 element ui 简单实现轮播图 本文,中间叙述的是过程,完整代码在最后面. 最近在写公司官网,用的是element ui 走马灯组件写的轮播图,ui想要自动缩放的效果,如上视频.在这里 ...

  6. vue uniapp 实现走马灯 ,文字横向滚动

    <!DOCTYPE html> <html><head><meta charset="utf-8"><title>vue ...

  7. vue+element之carousel走马灯的使用(The use of vue+element carousel)

    2022.10.13 大家好,今天我使用了vue+element实现走马灯的效果,类似于轮播图,可以进行一个图片的滑动. Hello, everyone. Today, I used vue+elem ...

  8. element 日期选择图标_element-ui日期组件DatePicker设置日期选择范围Picker Options

    element-UI提供了DatePicker日期选择器组件,可以让我们很方便的获取到日期,默认的选择是全部的日期都可以选择的,但是很多场景中我们要对日期选择范围做限定,比如出行日期就不能选过去的日期 ...

  9. vue积累——另一种走马灯

    效果图: vue源码: <template><el-carousel :interval="1500" type="card" height= ...

最新文章

  1. Viewpager的创建和使用——————————不懂的大家可以问,欢迎提问
  2. 自学python需要买书吗-Python真的适合每个人学习吗 学习Python需要多久
  3. python list 查找find_List 泛型 集合中 Find 的用法
  4. hdu I Hate It
  5. 13 登陆_《星球大战:弹珠台》中文版即将登陆Switch 12月13日正式发售
  6. 分治法求解序列最大最小元素【算法设计与分析】
  7. 第十三届蓝桥杯第二场模拟赛题解
  8. 车牌号上的省会简称;uni-app组件,vue组件通用,小程序可模仿
  9. Python接口自动化测试实战系列02
  10. 阿里云华北1235、华东1、华东2和华南1分别对应哪些城市?地域节点物理数据中心在哪?...
  11. 无线笔记本怎么连接服务器打印机驱动,笔记本怎么连接无线打印机驱动程序
  12. PCIe功耗控制--ASPM
  13. 《微观经济学》 第五章
  14. 分布式存储系统——HBase
  15. 【Java SE】第二话·第一个Java程序
  16. 等价无穷小替换及其习题 笔记
  17. 哈希表及哈希冲突避免
  18. python 根据经纬度 调取和显示地图_Python调用高德地图API实现经纬度换算、地图可视化-站长资讯中心...
  19. JOS学习笔记(九)
  20. t检验、Wilcoxon 符号秩检验、Mann-Whitney 秩和检验 Python实现

热门文章

  1. Redis性能测试工具benchmark简介
  2. 怎么理解Web 3.0?
  3. ppt里插入python(code)代码高亮
  4. 隐藏攻击面,提升信息安全防范能力
  5. 异常:Class net.sf.cglib.core.DebuggingClassWriter overrides final method visit
  6. 一个专家级软件架构师的自白书
  7. 虾皮shopee根据关键词取商品列表 API
  8. 手机端页面 自适应解决方案-收集
  9. Linux操作系统下的串口通信
  10. MyEcplise_Maven搭建SSM框架