你如何实现获取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")}