当前位置: 首页 > news >正文

创意实现!在uni-app小程序商品详情页轮播中嵌入视频播放功能

背景介绍

通过uni-app框架实现商城小程序商品详情页的视频与图片轮播功能,以提升用户体验和增加商品吸引力。通过展示商品视频和图片,用户可以更全面地了解商品细节,从而提高购买决策的便利性和满意度。这种功能适用于各类商品,如服装、家具、电子产品等。通过本文的步骤,您将学会如何在商城小程序中利用uni-app框架实现商品详情页的视频与图片轮播功能。

代码组件

新建文件:productConSwiper.vue

<template><view class='product-bg'><swiper :indicator-dots="indicatorDots" indicator-active-color="#E93323" :autoplay="autoplay":circular="circular" :interval="interval" :duration="duration" @change="change"><swiper-item v-if="videoline"><view class="item"><view v-if="!controls" style="width:100%;height:100% "><video id="myVideo" :src='videoline' objectFit="cover" controls style="width:100%;height:100% "show-center-play-btn show-mute-btn="true" auto-pause-if-navigate :custom-cache="false":enable-progress-gesture="false" :poster="imgUrls[0]" @pause="videoPause"></video></view><view class="poster" v-if="controls"><image class="image" :src="imgUrls[0]"></image></view><view class="stop" v-if="controls" @tap="bindPause"><image class="image" src="../../static/images/stop.png"></image></view></view></swiper-item><block v-for="(item,index) in imgUrls" :key='index'><swiper-item><image :src="item" class="slide-image" /></swiper-item></block></swiper></view>
</template><script>export default {props: {imgUrls: {type: Array,default: function() {return [];}},videoline: {type: String,value: ""}},data() {return {indicatorDots: true,circular: true,autoplay: true,interval: 3000,duration: 500,currents: "1",controls: true,isPlay: true,videoContext: null};},mounted() {if (this.videoline) {this.imgUrls.shift()this.videoContext = uni.createVideoContext('myVideo', this); // 创建videoContext}},methods: {videoPause(e) {},bindPause: function() { if (this.videoContext) {this.videoContext.play(); // 调用play方法this.$set(this, 'controls', false);this.autoplay = false;}},change: function(e) {this.$set(this, 'currents', e.detail.current + 1);}}}
</script><style scoped lang="scss">.product-bg {width: 100%;height: 750rpx;position: relative;}.product-bg swiper {width: 100%;height: 100%;position: relative;}.product-bg .slide-image {width: 100%;height: 100%;}.product-bg .pages {position: absolute;background-color: #fff;height: 34rpx;padding: 0 10rpx;border-radius: 3rpx;right: 30rpx;bottom: 30rpx;line-height: 34rpx;font-size: 24rpx;color: #050505;}#myVideo {width: 100%;height: 100%}.product-bg .item {position: relative;width: 100%;height: 100%;}.product-bg .item .poster {position: absolute;top: 0;left: 0;height: 750rpx;width: 100%;z-index: 9;}.product-bg .item .poster .image {width: 100%;height: 100%;}.product-bg .item .stop {position: absolute;top: 50%;left: 50%;width: 136rpx;height: 136rpx;margin-top: -68rpx;margin-left: -68rpx;z-index: 9;}.product-bg .item .stop .image {width: 100%;height: 100%;}
</style>

组件使用

import productConSwiper from '@/components/productConSwiper';
components: {productConSwiper,
},

sliderImage是一个图片地址数组
在这里插入图片描述

productInfo.video是视频的地址

<productConSwiper :imgUrls="sliderImage" :videoline="productInfo.video">
</productConSwiper>
http://www.lryc.cn/news/449367.html

相关文章:

  • WAF,全称Web Application Firewall,好用WAF推荐
  • docker中搭建nacos并将springboot项目的配置文件转移到nacos中
  • 概率论原理
  • MYSQL的安装和升级
  • 深入解析 RISC-V 递归函数的栈使用:以阶乘函数为例
  • 【保研纪念】计算机保研经验贴——南大cs、复旦cs、中南cs
  • TopOn对话游戏魔客:2024移动游戏广告应如何突破?
  • Chainlit集成LlamaIndex实现知识库高级检索(BM25全文检索器)
  • Dubbo入门案例
  • android设计模式的建造者模式,请举例
  • 【探索智谱AI的CogVideoX:视频生成的新前沿】
  • ant design vue做表单验证及form表单外验证、父子嵌套多个表单校验
  • 爱速搭百度低代码开发平台
  • 2024icpc(Ⅱ)网络赛补题E
  • mac怎么设置ip地址映射
  • StringReader 使用 JAXB自动将 XML 数据映射到 Java 对象
  • 【系统架构设计师】专题:系统分析和设计
  • Lambda表达式(Java)
  • 不同的子序列
  • CI24R1——精简版Si24R1,高性价比替代XN297开发资料
  • MySQL递归查询笔记
  • java中的位运算
  • llamafactory0.9.0微调qwen2vl
  • Electron 隐藏顶部菜单
  • 软件测试学习笔记丨curl命令发送请求
  • STM32+PWM+DMA驱动WS2812 —— 2024年9月24日
  • MMD模型及动作一键完美导入UE5-IVP5U插件方案(二)
  • C++函数指针
  • 汽车信息安全 -- 再谈车规MCU的安全启动
  • [Linux]从零开始的Linux的远程方法介绍与配置教程