function wxRequest(method, url, data) {
const app=getApp(); //设置一个全局的url ,
let baseUrl = app.globalData.baseUrl
return new Promise((resolve, reject) => {
let token = wx.getStorageSync('token')
wx.request({
url: baseUrl + url,
method: method,
data: data,
header: {
'content-type': method == 'GET' ? 'application/json' : 'application/x-www-form-urlencoded',
'Accept': 'application/json',
'token': token
},
dataType: 'json',
success: function(res) {
resolve(res.data);
},
fail: function(err) {
reject(err);
}
})
})
}
module.exports = { 暴露
myRequest: wxRequest
}
import { myRequest } from '../../utils/common.js' 在js中引入