fix(custom): 修复页面卸载时音频不停止的bug

This commit is contained in:
2024-01-21 19:41:00 +08:00
parent 1be8bca950
commit e14cf86631
2 changed files with 17 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { onBeforeUnmount, onMounted, ref } from 'vue'
import Taro from '@tarojs/taro'
import Lottie from 'lottie-web'
import * as dayjs from 'dayjs'
@@ -250,6 +250,7 @@ const startRun = (name: string) => {
setTimeout(() => {
bgUrl.value = wu
getUserInfo()
startMusic('https://files.wanzhuanyongcheng.com/file/music/yaotouzi/3.mp3', true)
}, 2000)
}, rotateSpeed * 1000)
}
@@ -364,6 +365,18 @@ const getBetJl = () => {
getBetList()
getList()
}
Taro.useDidHide(() => {
clearInterval(timeId.value)
clearInterval(time_i.value)
innerAudioContext.stop()
})
onBeforeUnmount(() => {
clearInterval(timeId.value)
clearInterval(time_i.value)
innerAudioContext.stop()
})
</script>
<template>

View File

@@ -307,6 +307,7 @@ const startRun = (name: string) => {
setTimeout(() => {
getList()
getUserInfo()
startMusic('https://files.wanzhuanyongcheng.com/file/music/yaotouzi/3.mp3', true)
}, 2000)
}, rotateSpeed * 1000)
}
@@ -416,10 +417,12 @@ const getBetJl = () => {
Taro.useDidHide(() => {
ws.value?.close()
innerAudioContext.stop()
})
onBeforeUnmount(() => {
ws.value?.close()
innerAudioContext.stop()
})
</script>