当前位置: 首页 > 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>

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 苹果更新过时产品:三款 Mac 成“古董”,九款 Mac 彻底“停产”
  • exebios提取工具通用exebios分离工具exe转编程器bios文件软件bios文件解密提取工具exe原厂bios提取烧录器bios芯片文件工具
  • Navicat Premium Lite 免费版 | 数据库连接类型简介
  • 如何更新Oracle表 LONG型的大文本学习
  • 解决mac下 Android Studio gradle 下载很慢,如何手动配置
  • 免费下载6组简历模板,让HR一眼相中你!
  • Redis——持久化策略
  • 速盾:高防cdn除了快还有什么好处?
  • 【R语言】fs 工具功能速查
  • K8s安装部署(v1.28)--超详细(cri-docker作为运行时)
  • 漫谈由标准输入\输出\错误输出引发的思考
  • 老挝旅游如何解决沟通问题?《老挝语翻译通》app支持语音识别翻译功能,能有效解决语言不同的痛点
  • 在Ubuntu 16.04上安装Anaconda Python发行版的方法
  • Java:小数操作
  • 几乎跪着读完这本Transformer经典神书,震撼到爆!!
  • [译]Python中的类属性与实例属性的区别
  • centos安装java运行环境jdk+tomcat
  • django开发-定时任务的使用
  • ESLint简单操作
  • JavaWeb(学习笔记二)
  • Js基础——数据类型之Null和Undefined
  • Redux系列x:源码分析
  • spark本地环境的搭建到运行第一个spark程序
  • web标准化(下)
  • 关键词挖掘技术哪家强(一)基于node.js技术开发一个关键字查询工具
  • 使用SAX解析XML
  • Semaphore
  • ‌U盘闪一下就没了?‌如何有效恢复数据
  • # 日期待t_最值得等的SUV奥迪Q9:空间比MPV还大,或搭4.0T,香
  • #NOIP 2014#Day.2 T3 解方程
  • (175)FPGA门控时钟技术
  • (19)夹钳(用于送货)
  • (Java)【深基9.例1】选举学生会
  • (Java数据结构)ArrayList
  • (zz)子曾经曰过:先有司,赦小过,举贤才
  • (附程序)AD采集中的10种经典软件滤波程序优缺点分析
  • (考研湖科大教书匠计算机网络)第一章概述-第五节1:计算机网络体系结构之分层思想和举例
  • (七)Flink Watermark
  • (十六)、把镜像推送到私有化 Docker 仓库
  • (收藏)Git和Repo扫盲——如何取得Android源代码
  • (四)opengl函数加载和错误处理
  • (循环依赖问题)学习spring的第九天
  • (转)大型网站架构演变和知识体系
  • (转)我也是一只IT小小鸟
  • *ST京蓝入股力合节能 着力绿色智慧城市服务
  • .NET C# 操作Neo4j图数据库
  • .NET COER+CONSUL微服务项目在CENTOS环境下的部署实践
  • .NET Core 中插件式开发实现
  • .NET 项目中发送电子邮件异步处理和错误机制的解决方案
  • .NET/C#⾯试题汇总系列:集合、异常、泛型、LINQ、委托、EF!(完整版)
  • .Net组件程序设计之线程、并发管理(一)
  • ?php echo ?,?php echo Hello world!;?
  • @data注解_SpringBoot 使用WebSocket打造在线聊天室(基于注解)
  • [240903] Qwen2-VL: 更清晰地看世界 | Elasticsearch 再次拥抱开源!
  • [ASP.NET MVC]Ajax与CustomErrors的尴尬