在封装HTTP 的时候 import 之后 new 对象的时候会报错
来源:7-11 HTTP类的封装与ES6 startsWith

苹果飞
2018-11-29
1回答
-
对比一下我的代码吧,应该就是export { HTTP }写错了吧
import { config } from '../config.js'
const tips = {
1: '报错,出现了一个错误',
1005: '不正确的开发者key',
3000: '不正确的开发者key'
}
class HTTP {
request (params) {
let { url, method = 'GET', data, header, success } = params
const { api_base_url, appkey } = config
wx.request({
url: api_base_url + url,
method,
data,
header: {
'content-type': 'application/json',
appkey
},
success: (res) => {
const { statusCode, data } = res
const { error_code } = data
if (statusCode.toString().startsWith('2')) {
success(data)
} else {
this._showError(error_code)
}
},
fail: (err) => {
this._showError(1)
}
})
}
_showError (errorCode) {
if (!errorCode) {
errorCode = 1
}
wx.showToast({
title: tips[errorCode],
icon: 'none',
duration: 3000
})
}
}
export { HTTP }
012018-12-18
相似问题