import { ref, onMounted } from 'vue'
export default {
setup() {
const videoRef = ref<HTMLVideoElement | null>(null)
function previewVideo(url: string) {
if (videoRef.value) {
videoRef.value.src = url
videoRef.value.load()
videoRef.value.play()
}
}
function handleVideoError() {
console.error('Video error occurred.')
// 你可以在这里添加错误处理逻辑,例如重试机制
// 或者通知用户发生了错误
// 例如,尝试重新加载视频
if (videoRef.value) {
videoRef.value.load()
videoRef.value.play()
}
}
onMounted(() => {
if (videoRef.value) {
videoRef.value.addEventListener('error', handleVideoError)
}
})
return {
videoRef,
previewVideo,
}
},
}