智慧画屏客户端
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
1.1 KiB

3 years ago
  1. import {
  2. baseURL
  3. } from './base.js'; //导入接口的前缀地址
  4. export const myRequest = (options) => {
  5. return new Promise((resolve, reject) => {
  6. uni.request({
  7. url: baseURL + options.url, //接口地址:前缀+方法中传入的地址
  8. method: options.method || 'GET', //请求方法:传入的方法或者默认是“GET”
  9. data: options.data || {}, //传递参数:传入的参数或者默认传递空集合
  10. headers: {
  11. 'Authorization ': window.localStorage.getItem('token') //自定义请求头信息
  12. },
  13. success: (res) => {
  14. //返回的数据(不固定,看后端接口,这里是做了一个判断,如果不为true,用uni.showToast方法提示获取数据失败)
  15. // if (res.data.success != true) {
  16. // return uni.showToast({
  17. // title: '获取数据失败',
  18. // icon: 'none'
  19. // })
  20. // }
  21. // 如果不满足上述判断就输出数据
  22. resolve(res);
  23. },
  24. // 这里的接口请求,如果出现问题就输出接口请求失败
  25. fail: (err) => {
  26. console.log(err);
  27. reject(err);
  28. }
  29. });
  30. });
  31. };