返回
创建于
状态
公开
vue 中 onBeforeUnmount 和 onMounted 的差别。
1<script setup>
2const audioPlayer = ref<HTMLAudioElement>(null!)
3// 需要使用 onBeforeUnmount,使用 onUnmouted 会出现 DOM 已经销毁的问题
4onBeforeUnmount(() => {
5 audioPlayer.value.pause()
6})
7</script>
8<template>
9 <audio ref="audioPlayer" hidden src="/silent.mp3" />
10</template>