Open2
fetchとaxios
JSONデータの取得
fetch
fetch("hoge/hoge")
.then((res) => res.json())
.then((data) => console.log(data)
axios
axios
.get("hoge/hoge")
.then((res) => console.log(res.data)
fetchでは受け取ってJSONに変換する必要がある。
axiosはエンコード不要。
どちらもPromiseベースなので.then
や.catch
が使える。
axiosでjson
axios
.get("hoge/hoge")
.then((res) => console.log(res.data)
ログインするとコメントできます