比如我需要封装这样一个获取用户ID的函数
getUserIds().then((ids) => {console.log(ids)})
// promise
const getUserIds = () => {
return new Promise(resolve){
// 模拟异步请求
setTimeout(() => { resolve([1,2,3]) })
}
}
// fetch
const getUserIds = () {
return fetch(URL, CONFIG)
}
用promise或者fetch来封装接口函数有什么区别吗?
梵蒂冈之花
一只斗牛犬
精慕HU
慕桂英546537
随时随地看视频慕课网APP
相关分类