promise 异步消息按顺序发送

115 阅读1分钟
const that = this
send(contentList[0], 0)
// 递归循环发送
async function send (item, i) {
  try {
    const res = await that.sendBeforePromise(item)
    i++
    if (i < contentList.length) {
      send(contentList[i], i)
    } else {
      hide()
    }
  } catch (e) {
    hide()
    that.$message.error('发送失败')
    console.error(`第${ i }条发送异常!`)
  }
}