index.js 931 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * @Author: 廖明明
  3. * @Date: 2022-03-30 15:54:48
  4. * @LastEditors: 廖明明
  5. * @LastEditTime: 2022-04-02 14:27:53
  6. * @Description:后端服务入口文件
  7. */
  8. import config from "./config.js";
  9. /**
  10. * @description:封装请求函数
  11. * @param {string} url 接口地址,以”/“开头
  12. * @param {object} data 请求参数
  13. * @param {string} method 请求类型
  14. * @param {object} header 请求头
  15. * @return {promise}
  16. * @author: 廖明明
  17. */
  18. export function request({ url = "", data = {}, method = "GET", header = {} }) {
  19. return new Promise((resolve) => {
  20. uni.request({
  21. method,
  22. url: config.baseUrl + url,
  23. data,
  24. header,
  25. dataType: "json",
  26. success(res) {
  27. console.log(res);
  28. resolve(res.data);
  29. },
  30. fail(err) {
  31. console.log(err);
  32. uni.showToast({
  33. icon: "none",
  34. title: "请求失败!",
  35. });
  36. },
  37. });
  38. });
  39. }