监听fetch的方法
重新封装fetch
function onFetch(callback) {
let logFetch = window.fetch
window.fetch = function (input, init) {
return new Promise((resolve, reject) => {
logFetch(input, init)
.then(function (response) {
callback(response)
resolve(response)
}, reject)
})
}
}
调用onFetch方法
onFetch(response => {
response.json()
.then(res=>{
console.log(res)
})
})