vue 多个audio播放 一个audio播放其他audio禁止播放
页面:
<div class="right">
<audio :ref="'audio' + index" :src="item.audioUrl" @ended="haveEnded"/>
<div :class="{ active: playIndex == index}" class="audio-component" @click="toReadAudio(index)" />
</div>
js代码
toReadAudio (index) {
let length = this.weekDetail.wordsRepeats.length || 0 // this.weekDetail.wordsRepeats是总共有几条音频数据
if (length) {
for (let i = 0; i < length; i++) {
let audioOne = 'audio' + i
audioOne = this.$refs[audioOne][0]
if (i === index) {
if (audioOne.paused) {
// 切换播放中的css样式
this.playIndex = index
audioOne.load()//音频重新加载,重新播放
audioOne.play()
} else {
audioOne.pause()
this.playIndex = null
}
} else {
audioOne.pause()
}
}
}
}
免责声明:文章转载自《vue 多个audio播放 一个audio播放其他audio禁止播放》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
上篇json与String的转化使用 minio 搭建私有对象存储云。aws-php-sdk 操作object下篇
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=