timeupdate事件:当前播放时间
<audio controls @timeupdate="timeUpdate"></audio>
将当前时间赋给current当前时间
timeUpdate(e){
console.log("时间变化",e.target.currentTime)
this.current=e.target.currentTime;
}
play()方法中判断是否处于暂停中,如果是点击播放,否则点击暂停
play(){
let audio = this.$refs.audio;
if(audio.paused){
audio.play();
}else{
audio.pause();
}
}
ended事件:播放完成触发(用来判断音频是否已播放结束)
<audio controls @ended="ended"></audio>
ended(){
console.log("播放完成")
}