axios拦截器怎么让他只弹出一次

100 阅读1分钟
function debounce(fn, wait) {
  let timerId = null
  let flag = true
  return function () {
    clearTimeout(timerId)
    if (flag) {
      fn.apply(this, arguments)
      flag = false
    }
    timerId = setTimeout(() => {
      flag = true
    }, wait)
  }
}

const authError = debounce((message) => {
  Message({
    message,
    type: 'warning'
  })
}, 1000)

// 拦截器里这样调
authError(response.data.msg)