request.js 565 B

123456789101112131415161718192021222324
  1. const BASE_URL = 'https://m.douban.com'
  2. export const newRequest = (options) => {
  3. return new Promise((resolve,reject)=> {
  4. uni.request({
  5. url: BASE_URL + options.url, //仅为示例,并非真实接口地址。
  6. method: options.method || 'GET',
  7. data: options.data || {},
  8. header: {
  9. 'custom-header': 'hello' //自定义请求头信息
  10. },
  11. success: (res) => {
  12. console.log(res.data);
  13. resolve(res);
  14. },
  15. fail:(err) => {
  16. uni.showToast({
  17. title:"请求失败"
  18. })
  19. reject(err);
  20. }
  21. });
  22. })
  23. }