• uniapp swiper轮播图片+视频


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

    <template>
        <view>
            <!--轮播图-->
    				<swiper :circular='true'  @change="videoplayObj.pause()" indicator-dots="true" indicator-color="#FCF3F3" indicator-active-color="#92C300" :autoplay="true" interval='5000' class='swiper-view'>
    					<swiper-item class="swiper-img" v-for="(item,index) in sliderImageArr" :key="index" >
    						<image mode='aspectFill' v-if="testingUrlIsImgOrVideo(item)=='image'" :src="item" @click='lookImg(item)'></image>
    						<video style="width: 100% !important;height: 530rpx;"  v-if="testingUrlIsImgOrVideo(item.url)=='video'" id="myVideo" ref="myVideoRef"
    															 :src="item"
    															:show-center-play-btn="true" :controls="true" object-fit="cover" >
    						</video>
    					</swiper-item>
    				</swiper>
        </view>
    </template>
    <script>
    export default {
    		components: {
    		
    		},
    		data() {
    			return {
    			sliderImageArr:['2022-08-26/202208261008569281562985416978497537.mp4','2.png'],//图片/视频路径我随便乱写的
    			videoplayObj: {}, //video对象
    			}
    			},
    			onLoad(option) {
    			this.videoplayObj = wx.createVideoContext('myVideo')
    		},
    		methods:{
    		//图片预览
     lookImg(e){
    				let array = [];
    				array.push(e);
    				uni.previewImage({
    					urls: array,
    					current: array
    				});
    },
    		//检验路径类型()图片/视频
     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) { 
    		suffix = ''
    	}
    	// 进行图片匹配
    	result = imgList.some(item => {
    		return item === suffix
    	})
    	if (result) {
    		result = 'image'
    	}else{
    		result = 'video'
    	}
    	console.log('检测',result);
    	return result
         }
    	}
    	}
    </script>
    <style>
    	// 自定义轮播加视频
    	.swiper-view {
    		width: 100%;
    		height: 530rpx;
    	
    		.swiper-img {
    			image {
    				width: 100%;
    				height: 530rpx;
    			}
    		}
    	
    	}
    	// 指示点元素激活(当前选中)状态样式 */
    		::v-deep wx-swiper .wx-swiper-dot-active{
    			width: 30rpx;
    			height: 14rpx;
    			border-radius: 6rpx;
    			background-color: #92C300;
    			}
    </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
  • 相关阅读:
    双胶合透镜初始设计
    第二次笔记: 无符号整数的表示和运算 有符号整数的表示和运算 原码 补码 反码 移码
    golang设计模式——装饰器模式
    uniapp使用pinia状态管理永久缓存方法
    groovy:调用jenkins任务时的请求失败问题
    编程语言新特性:instanceof的改进
    谁说.NET没有GC调优?只改一行代码就让程序不再占用内存
    SpringCloud——网关Gateway
    二叉搜索树
    HTTPS —— HTTPS的加密方式
  • 原文地址:https://blog.csdn.net/oneya1/article/details/126586284