就报这种错误 我封装的代码如下
onst Config = require(’./config.js’) //导入自定义配置文件
const http = ({
url = ‘’, //请求地址
param = {}, //请求参数
contentType, //请求头
method = “GET”, //请求方式
isPermissions = false //是否认证
} = {}) => {
//设置请求头
let header = {
“content-type”: contentType ? contentType : method == ‘POST’ ? ‘application/x-www-form-urlencoded’ : ‘application/json’,
}
if (isPermissions) {
//添加token到header中
header.token = wx.getStorageSync(‘token’)
}
let timeStart = Date.now(); //开始请求时间
return new Promise((resolve, reject) => {
wx.request({
url: getUrl(url),
data: param,
header: header,
method: method,
complete: (res) => {
console.log(`请求地址:${getUrl(url)}`);
console.log(`请求参数:${JSON.stringify(param)}`);
console.log(`耗时${Date.now() - timeStart}ms`);
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(res)
} else if (res.statusCode === 500) {
console.log(res)
// _login()
reject(res)
} else {
reject(res)
}
}
})
})
}
//获取请求地址
const getUrl = (url) => {
if (url.indexOf(’://’) == -1) {
url = Config.BaseUrl + url;
}
return url
}
// get方法
const _get = (url, param = {}, isPermissions) => {
return http({
url,
param,
isPermissions
})
}
const _post = (url, param = {}, isPermissions, contentType) => {
return http({
url,
param,
method: ‘POST’,
isPermissions,
contentType
})
}
}
module.exports = {
_get,
_post
}
我请求的接口是这样的:
const netWorke = require(’./utils/network2.js’) //network2.js就是封装的Promise请求
netWorke._get(‘wxorder/GetMerchant’, {}, false).then(res => {
console.log(res)
})
有大神能帮帮我不