时空网前端
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.

31 lines
714 B

  1. const install = (Vue, vm) => {
  2. // 请求全局配置
  3. Vue.prototype.$u.http.setConfig({
  4. baseUrl: vm.API.DEVURL,
  5. method: 'POST',
  6. dataType: 'json', // 返回数据时自动 JSON.parse()
  7. showLoading: true, // 是否显示请求中的loading
  8. loadingText: '正在加载',
  9. loadingTime: 800 // 延迟800毫秒时显示加载框
  10. });
  11. // 请求前拦截
  12. Vue.prototype.$u.http.interceptor.request = config => {
  13. return true;
  14. };
  15. // 响应拦截
  16. Vue.prototype.$u.http.interceptor.response = res => {
  17. if(res.code == 200) {
  18. return res.result;
  19. } else if(res.code == 201) {
  20. console.log("其他状态:", res.code)
  21. return false;
  22. } else {
  23. return false;
  24. }
  25. }
  26. }
  27. export default {
  28. install
  29. }