uniapp自定义组件的使用--记录
2024-10-21 07:31:46
在 pages.json同级目录下 创建目录和文件:
components:
videoComp:
VideoPlaySelf.vue
VideoPlaySelf.vue 内容
<template>
<video class="video" id="myVideo"
:loop="false" direction="0" :src="videoUrl" @click="$emit('hideElement')" autoplay :controls="false"
@loadedmetadata="$emit('loadedmetadataStart',$event)" @timeupdate="$emit('videoTimeUpdate',$event)"
@ended="$emit('palyNextVideo',sectionId)" :show-center-play-btn="false" :show-play-btn="false"
:show-fullscreen-btn="false" :enable-progress-gesture="false">
</video>
</template> <script lang="ts">
import { defineComponent } from 'vue'
import nav from '@/utils/nav' export default defineComponent({
name: 'VideoPlaySelf',
props: ["videoUrl",'sectionId'],
data() { },
methods: {
getVideoContext() {
return nav.uniSelf.createVideoContext('myVideo', this);
},
videoPlay() {
nav.uniSelf.createVideoContext('myVideo', this).play();
},
videoPause() {
nav.uniSelf.createVideoContext('myVideo', this).pause();
},
videoSeek(second: number) {
nav.uniSelf.createVideoContext('myVideo', this).seek(second);
}
} })
</script> <style lang="scss">
.video {
position: absolute;
width: 100vw;
height: 100vh;
}
</style>
在对应的vue页面引入:
<template>
<view>
...
<VideoPlaySelf
style="position: absolute; width: 100vw; height: 100vh;"
v-if="current === index && (item.videoUrl !== '')"
ref='videoPlaySelf'
:videoUrl="item.videoUrl" :sectionId="item.sectionId"
@hideElement="hideElement" @loadedmetadataStart="loadedmetadataStart" @videoTimeUpdate="videoTimeUpdate"
@palyNextVideo="palyNextVideo"> </VideoPlaySelf>
...
</view>
</template>
<script lang="ts">
import VideoPlaySelf from '@/components/videoComp/VideoPlaySelf.vue'; export default defineComponent({
components: {
VideoPlaySelf
}
...
</script>
最新文章
- Python导出Excel为Lua/Json/Xml实例教程(三):终极需求
- ASP.NET 对于文件的下载与上传
- JAVA 语法基础综合练习——学生成绩管理系统
- Entity Framework技术导游系列 开篇 (转)
- Apache(Web)服务器性能调整
- 递归遍历树结构顺序显示并且添加到list集合
- Kali Linux 优化过程
- OSS研究
- HDOJ 1334 Perfect Cubes(暴力)
- SED&;AWK
- java.lang.ClassCastException: org.springframework.web.filter.CharacterEncodingFilter cannot be cast to javax.servlet.Filter
- 转: Apache开启gzip
- 百度地图 iOS SDK - 坐标转换方法
- redis持久化的几种方式
- 【Bootstrap】bootstrap-datetimepicker日期时间插件
- python css选择器
- MySQL系列详解五: xtrabackup实现完全备份及增量备份详解-技术流ken
- 二维数组遍历的方式(for普通循环遍历、foreach循环遍历、toString方式遍历)
- rpm命令如何打印调试信息?
- CSS:绝对定位布局案例 position布局实例