fetch(url)
.then((response) => {
let reader = response.body.getReader()
let decoder = new TextDecoder('utf-8')
return reader.read().then((result) => {
return decoder.decode(result.value)
})
})
.then((csvData) => {
Papa.parse(csvData, {
complete: this.getData,
header: true
})
})
.catch((error) => {
console.log(error)
})
function myFetch(params){
return new Promise(function(resolve, reject){
const xhr = new XMLHttpRequest();
xhr.open(params.method, params.url, true);
xhr.send();
xhr.addEventListener('readystatechange', function(e){
if( xhr.readyState != 4 ) return;
if( xhr.status == 200 ){
resolve( xhr.responseText );
} else{ reject( xhr.statusText ); }
});
}
myFetch(//parameters...).then(//...... код который у Вас в then).