“Async -Funktionssyntax” Code-Antworten

Async erwartet

const data = async ()  => {
  const got = await fetch('https://jsonplaceholder.typicode.com/todos/1');
  
  console.log(await got.json())
}

data();
Salo Hopeless

Async -Funktionssyntax

const foo = async () => {
   await// do something
}
// OR
async function foo() {
  await// do something
}
Inquisitive Iguana

Asynchron/wartet

async function run () {
  const user = await getUser()
  const tweets = await getTweets(user)
  return [user, tweets]
}
 
 
Motionless Mallard

Async erwartet

async function f() {

  try {
    let response = await fetch('/no-user-here');
    let user = await response.json();
  } catch(err) {
    // catches errors both in fetch and response.json
    alert(err);
  }
}

f();
Yawning Yak

Async erwartet JS

fetch('coffee.jpg')
.then(response => {
  if (!response.ok) {
    throw new Error(`HTTP error! status: ${response.status}`);
  } else {
    return response.blob();
  }
})
.then(myBlob => {
  let objectURL = URL.createObjectURL(myBlob);
  let image = document.createElement('img');
  image.src = objectURL;
  document.body.appendChild(image);
})
.catch(e => {
  console.log('There has been a problem with your fetch operation: ' + e.message);
});
Tired Toucan

Ähnliche Antworten wie “Async -Funktionssyntax”

Fragen ähnlich wie “Async -Funktionssyntax”

Weitere verwandte Antworten zu “Async -Funktionssyntax” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen