Reputation: 27
I am trying to load the Ag-grid. I saw this code sample, but I don’t know why they use two times .then
. Can anyone help me to understand it?
Thank you
beforeMount() {
this.columnDefs = [
{headerName: 'Make', field: 'make'},
{headerName: 'Model', field: 'model'},
{headerName: 'Price', field: 'price'}
];
fetch('https://api.myjson.com/bins/15psn9')
.then(result => result.json())
.then(rowData => this.rowData = rowData);
}
Upvotes: 0
Views: 163
Reputation: 7049
Because your response.json()
call itself returns another Promise, as you can read up in the documentation about Body.json()
. The reason for that is that response body contains a stream that needs to get parsed and converted into JS data structures before you can use it.
Upvotes: 1