【发布时间】:2018-03-10 03:47:00
【问题描述】:
我使用下面的代码来返回工作的承诺OK.
承诺返回 data 值
run: () => {
return new Promise((resolve, reject) => {
....
}).then((data) => {
let loginApi = data[0]
let test = 1;
}).catch((err) => {
if (err.statusCode === 302) {
var data = url.parse(err.response.headers.location, true)
resolve(data )
}
})
});
我叫它
module.run()
.then((data) => {
我能够得到数据。
现在我想在解析中返回值test,我该怎么做?
我尝试像这样添加它
resolve({data,test});
resolve([data,test]);
与调用类似
module.run()
.then({data,test}) => {
没有成功(测试为空),我读到了spread,但这是唯一的选择吗?
我使用ES6 和bluebird 最新版本
【问题讨论】:
-
resolve({data,test});和resolve([data,test]);都可以,调用端是什么样的?.. 请注意,为什么只解决错误? -
@Keith - 像这个 module.run() .then({data,test}) => {
-
@Ninawatcher
.then({data,test}) => {- 你在这里缺少一个左括号:.then(({data,test}) => { ... -
试试 ->
module.run() .then( ({data,test}) => { }) -
@CodingIntrigue - 谢谢你是对的!!!
标签: javascript ecmascript-6 promise bluebird