Welcome to Qi-U Community for programmer and developer-Open, Learning and Share

Categories

0 votes
265 views
in Technique[技术] by (31.9m 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

Please log in or register to answer this question.

1 Answer

0 votes
by (31.9m points)

代码相当于

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

所以会报错


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