responseInterceptors.js 771 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * 响应拦截
  3. * @param {Object} http
  4. */
  5. module.exports = (vm) => {
  6. uni.$u.http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/
  7. const data = response.data
  8. // 自定义参数
  9. const custom = response.config?.custom
  10. if (data.code == 200) {
  11. return res;
  12. } else if (data.code == 401) {
  13. uni.showToast({
  14. title: 'Token失效',
  15. icon: 'none',
  16. duration: 2000
  17. })
  18. } else {
  19. uni.showToast({
  20. title: data.msg,
  21. icon: 'none',
  22. duration: 2000
  23. })
  24. }
  25. return data.data || {}
  26. }, (response) => {
  27. return Promise.reject(response)
  28. })
  29. }