• swiper轮播图片+视频播放,预览及页面跳转功能


    1.效果在这里插入图片描述
    2.上代码

    <template>
    <swiper :circular='true' indicator-dots="true" @change="changeSwiper" :autoplay="true" interval='5000' class='swiper-view'>
    				<swiper-item class="swiper-img" v-for="(item,index) in swiperList" :key="index" >
    					<!-- 预览 lookImg(item) -->
    					<!-- $utils.navigateTo(item.uniapp_url,{id:item.typeId}) -->
    					<image mode='aspectFit' v-if="testingUrlIsImgOrVideo(item.pic)=='image'" :src="item.pic" @click='skipTo(item)'></image>
    					<video style="width: 100% !important;height: 410rpx;"  v-if="testingUrlIsImgOrVideo(item.pic)=='video'" id="myVideo" ref="myVideoRef"
    														 :src="item.pic"
    														:show-center-play-btn="true" :controls="true" object-fit="cover" >
    					</video>
    				</swiper-item>
    			</swiper>
    </template>
    <script>
    export default {
    data() {
    			return {
    			current:0,
    							videoplayObj: {}, //video对象
    			swiperList: [
    			{pic:'https://img2.baidu.com/it/u=1395980100,2999837177&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1670000400&t=9308d9514d40e0c81de4559a536d0669',typeId:1,uniapp_url:'页面路径'},
    			{pic:'https://img2.baidu.com/it/u=1395980100,2999837177&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1670000400&t=9308d9514d40e0c81de4559a536d0669',typeId:2,uniapp_url:'页面路径'}
    			],
    			}
    			},
    			onLoad(res) {
    						this.videoplayObj = wx.createVideoContext('myVideo')
    },
    			methods:{
    			skipTo(item){
    			this.lookImg(item.pic)
    			},
    			//检验路径类型()图片/视频
    testingUrlIsImgOrVideo(url){
    	// console.log('拿到路径',url);
    	let array = [];
    	// // 匹配 视频
    	const imgList = [
    		'png', 'jpg', 'jpeg', 'bmp', 'gif', 'PNG','JPG','JPEG','BMP','GIF','webp','WEBP','psd','PSD','svg','SVG','tiff','TIFF'
    	]
    	// 后缀获取
    	let suffix = ''
    	// 获取类型结果
    	let result = ''
    	try {
    		const flieArr = url.split('.') //根据.分割数组
    		suffix = flieArr[flieArr.length - 1] //取最后一个
    		// console.log('取末尾', suffix)
    	} catch (err) { //如果fileName为空等.split方法会报错,就走下面的逻辑
    		suffix = ''
    	}
    	// 进行图片匹配
    	result = imgList.some(item => {
    		return item === suffix
    	})
    	if (result) {
    		result = 'image'
    	}else{
    		result = 'video'
    	}
    	// console.log('检测',result);
    	return result
    }}
    	},
    	//图片预览
    lookImg(e){
    				// console.log('22222',e)
    				let array = [];
    				array.push(e);
    				uni.previewImage({
    					urls: array,
    					current: array
    				});
    }	,
    changeSwiper(e){
    				// console.log('改变',e)
    				this.current = e.current;
    				this.videoplayObj.pause()
    			},		
    }
    }
    </script>
    <style>
    	// 自定义轮播加视频
    	.swiper-view {
    		width: 100%;
    		height: 410rpx;
    	
    		.swiper-img {
    			// margin: 0 10px;
    			image {
    				width: 100%;
    				height: 410rpx;
    			}
    		}
    	
    	}
    </style>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
  • 相关阅读:
    这可能是最全的 SpringBoot3 新版本变化了
    Ubuntu22.04安装nvidia-docker
    动手实现深度学习(5):计算图的实现
    【强化学习】Sarsa算法求解悬崖行走问题 + Python代码实战
    【Java第33期】:在普通的Maven项目中存储Bean对象并获取和使用
    C++——多态
    使用Vite快速构建Vue3+ts+pinia脚手架
    Java经典面试题集
    CocosCreator:背景滚动 、背景循环滚动
    众和策略:题材股什么意思?
  • 原文地址:https://blog.csdn.net/oneya1/article/details/128135828