util.js 673 B

123456789101112131415161718192021222324252627282930
  1. const requst = (opt) => {
  2. opt = opt || {};
  3. opt.url = opt.url || '';
  4. opt.data = opt.data || null;
  5. opt.method = opt.method || 'POST';
  6. opt.header = opt.header || {
  7. "Content-Type": "application/x-www-form-urlencoded"
  8. };
  9. opt.success = opt.success || function () {};
  10. uni.request({
  11. url: opt.url,
  12. data: opt.data,
  13. method: opt.method,
  14. header: opt.header,
  15. dataType: 'json',
  16. success: function (res) {
  17. opt.success(res);
  18. },
  19. fail: function () {
  20. uni.showToast({
  21. title: '请稍后重试'
  22. });
  23. }
  24. })
  25. }
  26. export {
  27. requst
  28. }