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.
|
|
import { baseURL } from './base.js'; //导入接口的前缀地址
export const myRequest = (options) => { return new Promise((resolve, reject) => { uni.request({ url: baseURL + options.url, //接口地址:前缀+方法中传入的地址
method: options.method || 'GET', //请求方法:传入的方法或者默认是“GET”
data: options.data || {}, //传递参数:传入的参数或者默认传递空集合
headers: { 'Authorization ': window.localStorage.getItem('token') //自定义请求头信息
}, success: (res) => { //返回的数据(不固定,看后端接口,这里是做了一个判断,如果不为true,用uni.showToast方法提示获取数据失败)
// if (res.data.success != true) {
// return uni.showToast({
// title: '获取数据失败',
// icon: 'none'
// })
// }
// 如果不满足上述判断就输出数据
resolve(res); }, // 这里的接口请求,如果出现问题就输出接口请求失败
fail: (err) => { console.log(err); reject(err); } }); }); };
|