feat: 视频播放器风格修正,卸载页面时卸载视频播放器
This commit is contained in:
1 parent
1f6c924e11
commit
632a562348
3 files changed
+35
-22
No files matched your search
@@ -10,7 +10,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { VirtualFile } from '@/class/VirtualDirectory';
|
||||
import miaoDropHandler from '@/components/miaoDropHandler.vue';
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { onBeforeUnmount, onMounted, ref } from 'vue';
|
||||
import useViretualPages from '@/hooks/useVirtualPages';
|
||||
import XGPlayer from 'xgplayer'
|
||||
import '@/style/xgplayer.scss'
|
||||
@@ -29,13 +29,13 @@ const view = views.getView(props.id)
|
||||
const videoPath = ref<string>('');
|
||||
const xgPlayer = ref()
|
||||
|
||||
let _player: XGPlayer
|
||||
const setVideo = (() => {
|
||||
let player: any
|
||||
return (url: string) => {
|
||||
if (player) {
|
||||
player.src = url
|
||||
if (_player) {
|
||||
_player.src = url
|
||||
} else {
|
||||
player = new XGPlayer({
|
||||
_player = new XGPlayer({
|
||||
el: xgPlayer.value,
|
||||
url,
|
||||
width: '100%',
|
||||
@@ -74,6 +74,10 @@ onMounted(() => {
|
||||
setVideo(currentFiles.value[0].url)
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
_player.destroy()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
Reference in new issue
Block a user