React with fetch Api

React with fetch Api

2016, Jul 26    

参见 传统 Ajax 已死,Fetch 永生

使用ES7 aysnc/await语法后代码的整洁了不少。

try {
  let response = await fetch(url);
  let data = await response.json();
  console.log(data);
} catch(e) {
  console.log("Oops, error", e);
}