海南旅游项目 前端仓库
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.

39 lines
938 B

4 years ago
4 years ago
4 years ago
4 years ago
  1. const install = (Vue, vm) => {
  2. // 请求地址
  3. let baseUrl = vm.API.PRODURL;
  4. if(vm.API.DEV == 'dev'){
  5. baseUrl = vm.API.DEVURL;
  6. };
  7. // 请求全局配置
  8. Vue.prototype.$u.http.setConfig({
  9. baseUrl: baseUrl,
  10. method: 'POST',
  11. dataType: 'json', // 返回数据时自动 JSON.parse()
  12. showLoading: true, // 是否显示请求中的loading
  13. loadingText: '正在加载',
  14. loadingTime: 800 // 延迟800毫秒时显示加载框
  15. });
  16. // 请求前拦截, 现在不做拦截
  17. Vue.prototype.$u.http.interceptor.request = config => {
  18. console.log(config)
  19. return true;
  20. };
  21. // 响应拦截
  22. Vue.prototype.$u.http.interceptor.response = res => {
  23. if(res.code == 0) {
  24. return res;
  25. } else if(res.code == -2) {
  26. this.$url('/page/login/index');
  27. uni.clearStorageSync('userinfo');
  28. }else {
  29. vm.$msg(res.msg);
  30. return false;
  31. }
  32. // res.code == 9998 手机号 res.code == 9999 用户信息
  33. }
  34. }
  35. export default {
  36. install
  37. }