我从不使用这种语言,只帮助一个朋友。我正在尝试播放一个字的声音。但是执行速度很快。
audio.vue
methods: {
.then(setTimeout(() => {
const arr = 'test'
Array.prototype.forEach.call(arr, char => {
audio.playChar(char) //Passing each char separately, wait 1 second before execure next iterator
})
},
...
}
}
audio.js
playTest (char) {
return new Promise((resolve, reject) => {
const audio = new Audio()
audio.src = `.../alert/pt/${char}.mp3` //playing separately but very quickly
audio.onended = resolve
audio.onerror = reject
audio.play()
})
},
答案 0 :(得分:1)
如果要延迟每次执行该函数,请在该函数之后的setTimeout中添加一个整数。
audio.vue:
methods: {
.then(setTimeout(() => {
const arr = 'test'
Array.prototype.forEach.call(arr, char => {
audio.playChar(char) //Passing each char separately, wait 1 second before execure next iterator
})
}, 1000 //<== add 1000 milliseconds to your setTimeout
...
}
}