0
点赞
收藏
分享

微信扫一扫

使用fetch请求数据

AbrahamW 2022-07-01 阅读 153

第一种写法:

getData() {
fetch('/api/list_all').then(res => {
return res.json()
})
.then(res => {
if(res.code === 200) {

}
})
.catch(err => {
console.log(err)
})
}

第二种写法:

async getData() {
try {
const result = await fetch('/api/list_all')
const res = await result.json()
if (res.code === 200) {

}
} catch (error) {
console.log(error)
}
}

 


举报

相关推荐

0 条评论