比如我需要封裝這樣一個獲取用戶ID的函數 getUserIds().then((ids) => {console.log(ids)})// promiseconst getUserIds = () => { return new Promise(resolve){ // 模擬異步請求 setTimeout(() => { resolve([1,2,3]) })}}// fetchconst getUserIds = () { return fetch(URL, CONFIG)}用promise或者fetch來封裝接口函數有什么區別嗎?
Promise和fetch封裝API請求的區別
梵蒂岡之花
2019-03-13 14:15:21