处理vue子组件emit事件警告

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
灌糖包子 2026-04-28 22:32:04 +08:00
parent c55b75686e
commit 83a814c386
Signed by: sookie
GPG Key ID: 0599BECB75C1E68D

View File

@ -122,6 +122,8 @@ const MEDIA_EVENTS = [
'waiting', 'waiting',
] as const ] as const
type MediaEventName = typeof MEDIA_EVENTS[number]
let activeMutex: PlayerExpose | null = null let activeMutex: PlayerExpose | null = null
const props = defineProps({ const props = defineProps({
@ -186,14 +188,39 @@ const props = defineProps({
}, },
}) })
const emit = defineEmits<{ const emit = defineEmits([
(event: 'update:music', value: PlayerMusicItem): void 'update:music',
(event: 'update:muted', value: boolean): void 'update:muted',
(event: 'update:volume', value: number): void 'update:volume',
(event: 'update:shuffle', value: boolean): void 'update:shuffle',
(event: 'update:repeat', value: RepeatValue): void 'update:repeat',
(event: string, payload?: Event): void 'abort',
}>() 'canplay',
'canplaythrough',
'durationchange',
'emptied',
'encrypted',
'ended',
'error',
'interruptbegin',
'interruptend',
'loadeddata',
'loadedmetadata',
'loadstart',
'mozaudioavailable',
'pause',
'play',
'playing',
'progress',
'ratechange',
'seeked',
'seeking',
'stalled',
'suspend',
'timeupdate',
'volumechange',
'waiting',
] as const)
const audio = ref<HTMLAudioElement | null>(null) const audio = ref<HTMLAudioElement | null>(null)
const internalMusic = ref<PlayerMusicItem>(props.music) const internalMusic = ref<PlayerMusicItem>(props.music)
@ -562,7 +589,7 @@ function initAudio() {
media.volume = props.volume media.volume = props.volume
MEDIA_EVENTS.forEach((eventName) => { MEDIA_EVENTS.forEach((eventName) => {
media.addEventListener(eventName, (event) => emit(eventName, event)) media.addEventListener(eventName, (event) => emitMediaEvent(eventName, event))
}) })
media.addEventListener('play', onAudioPlay) media.addEventListener('play', onAudioPlay)
@ -585,6 +612,10 @@ function setSelfAdaptingTheme(color: string | null) {
selfAdaptingTheme.value = color selfAdaptingTheme.value = color
} }
function emitMediaEvent<T extends MediaEventName>(eventName: T, event: Event) {
emit(eventName, event)
}
watch(() => props.music, (music) => { watch(() => props.music, (music) => {
internalMusic.value = music internalMusic.value = music
}) })