request.js 805 B

123456789101112131415161718192021222324252627282930
  1. const BASE_URL = 'https://www.waywish.com';
  2. export function request(options) {
  3. return new Promise((resolve, reject) => {
  4. uni.request({
  5. url: BASE_URL + options.url, // 服务器url
  6. method: options.method || 'GET', // 请求方法,默认为GET
  7. data: options.data || {}, // 请求参数
  8. header: options.header || {
  9. 'Content-Type': 'application/json'
  10. }, // 设置请求的 header
  11. success: (res) => {
  12. // 请求成功
  13. if (res.statusCode === 200) {
  14. resolve(res.data);
  15. } else {
  16. // 可以根据项目要求修改错误处理
  17. reject(res.data);
  18. }
  19. },
  20. fail: (err) => {
  21. // 请求失败处理
  22. uni.showToast({
  23. title: '出错了,请联系管理员~',
  24. icon: 'none'
  25. })
  26. reject(err);
  27. },
  28. });
  29. });
  30. };