如何从异步函数返回值?
我试过了,但它不起作用:
var x;
getText("http://localhost/test/test.html").then(data => {x = data});
async function getText(file) {
let myObject = await fetch(file);
let myText = await myObject.json();
return myText;
}
alert(x);