const baseUrl = 'https://www.szdeao.com' //请求接口地址 let isJson=true const httpRequest = (url, method, data,isJson) => { let meth = method.toUpperCase();//小写改为大写 if (!data) { data = {} } if(getApp().globalData.token){ data['token'] = getApp().globalData.token; //token } // let httpDefaultOpts = { url: baseUrl + url, data: data, method: meth, header:{ 'X-Requested-With': 'XMLHttpRequest', 'content-type': isJson==false ? 'application/x-www-form-urlencoded;charset=UTF-8' : 'application/json',//判断需要json格式还是formData格式传参 // 'content-type': 'application/json', }, dataType: 'json', } return new Promise(function(resolve, reject) { uni.request(httpDefaultOpts).then( (res) => { console.log(res) // if(res[1].data.code == 0){//成功返回 // resolve(res[1].data) // }else{//错误信息 // uni.showToast({ // title:res[1].data.msg, // icon:'none' // }) // //resolve(res[1]) //错误信息返不返回 看个人情况 // } resolve(res[1].data) } ).catch((response) => { reject(response) } ) }) }; export default { baseUrl, httpRequest }