[英]How do you implement the fetch api?
我不明白,如何在Kotlin中實現提取API的代碼:
var smf: dynamic = js("({})")
smf.method = "GET"
smf.mode = "cors"
smf.cache = "default"
window.fetch(url, smf)
.then({response -> {
console.log("response")
}})
.catch({error ->
console.error("error")
})
而且根本不起作用。 沒有控制台消息,也沒有
我的猜測是問題出在您的第一個lambda中:
.then({response -> {
console.log("response")
}})
該代碼不執行任何操作,因為它等效於:
.then(fun(response: dynamic){
return {console.log("response")} // creates a lambda and returns it for no reason
})
TL; DR要修復代碼,請除去第二對花括號:
.then {response -> console.log("response")}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.