亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Js鏈式調用如何加條件?

Js鏈式調用如何加條件?

慕的地8271018 2019-03-07 14:15:34
我想用 userProxy 判斷是否加上.proxy(),應該怎么樣優雅實現呢。if (useProxy) {  data = await superAgent    .get(send.url)    .proxy(proxy)    .query(send.query)    .timeout({      response: 8000    })    .set({      'Content-Type': 'application/x-www-form-urlencoded'    })} else {  data = await superAgent    .get(send.url)    .query(send.query)    .timeout({      response: 15000    })    .set({      'Content-Type': 'application/x-www-form-urlencoded'    })}
查看完整描述

2 回答

?
婷婷同學_

TA貢獻1844條經驗 獲得超8個贊

運用三目運算符


查看完整回答
反對 回復 2019-03-17
?
拉風的咖菲貓

TA貢獻1995條經驗 獲得超2個贊

let agent = await superAgent.get(send.url)

if(useProxy){

    agent = await agent.proxy(proxy)

}

data = await agent.query(send.query)

    .timeout({

      response: 8000

    })

    .set({

      'Content-Type': 'application/x-www-form-urlencoded'

    })

這樣應該可以吧,不太確定哪里有異步,都加個await總沒錯


查看完整回答
反對 回復 2019-03-17
  • 2 回答
  • 0 關注
  • 640 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號