Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
587 views
in Technique[技术] by (71.8m points)

axios拦截器里,让结果晚5秒钟返回就错了,为什么。。请问怎么写比较好?谢谢

axios.interceptors.response.use(data => { // 响应成功关闭loading
  setTimeout(function () {
    console.log("inter-response")
  }, 5000)
  return data
},

改成下面这样,5秒后再返回结果就发生错误

axios.interceptors.response.use(data => { // 响应成功关闭loading
  setTimeout(function () {
    console.log("inter-response")
    return data
  }, 5000)
  
},

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

代码相当于

axios.interceptors.response.use(data => { // 响应成功关闭loading
  setTimeout(function () {
    console.log("inter-response")
    return data
  }, 5000)
  return undefined
},

所以会报错


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...