Rumah > Soal Jawab > teks badan
怪我咯2017-04-17 15:34:07
(err,res,body)=>{}是回调吧
应该这么写吧
(err,res)=>{
if(err){
throw err
}else{
return (
//对res进行操作
)
}
}
res应该是后台返回的数据,不知道格式,只能写个思路。
高洛峰2017-04-17 15:34:07
// callback
function rqst(callback) {
request({}, (err, res, body) => {
if (err) return callback(err);
callback(null, body);
})
}
rqst(function(err, body) {
// body
})
// promise
function rqst() {
return new Promise(resolve, reject) => {
request({}, (err, res, body) => {
if (err) reject(err);
resolve(body)
})
}
}
rqst.then(body => {
// body
}).catch(e => {
})