租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
927 B

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
  1. /**
  2. * 响应拦截
  3. * @param {Object} http
  4. */
  5. export const responseInterceptors = (vm) => {
  6. uni.$uv.http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/
  7. const data = response.data
  8. if (data.code == 200 || data.code == 905) {
  9. return Promise.resolve(data);
  10. }else if(data.code === 500 && (data.message == '操作失败,token非法无效!' || data.message == '操作失败,用户不存在!')){
  11. uni.removeStorageSync('token')
  12. uni.removeStorageSync('userInfo')
  13. uni.removeStorageSync('sessionKey')
  14. uni.navigateTo({
  15. url:"/pages/auth/index"
  16. })
  17. return;
  18. }else{
  19. uni.$uv.toast(data.message)
  20. return Promise.reject(data)
  21. }
  22. }, (response) => { /* 对响应错误做点什么 (statusCode !== 200)*/
  23. console.info('interceptors.response---------',data)
  24. return Promise.reject(response)
  25. })
  26. }