1234567891011121314151617181920212223242526272829303132 |
- const BASE_URL = 'https://www.waywish.com';
- export function request(options) {
- return new Promise((resolve, reject) => {
- let header = options.header || {
- 'Content-Type': 'application/json'
- }
- if (uni.getStorageSync('token')) header['token'] = uni.getStorageSync('token');
- uni.request({
- url: BASE_URL + options.url, // 服务器url
- method: options.method || 'GET', // 请求方法,默认为GET
- data: options.data || {}, // 请求参数
- header: header, // 设置请求的 header
- success: (res) => {
- // 请求成功
- if (res.statusCode === 200) {
- resolve(res.data);
- } else {
- // 可以根据项目要求修改错误处理
- reject(res.data);
- }
- },
- fail: (err) => {
- // 请求失败处理
- uni.showToast({
- title: '出错了,请联系管理员~',
- icon: 'none'
- })
- reject(err);
- },
- });
- });
- };
|