Vue.js template: Use async/await
This commit is contained in:
parent
40603f1566
commit
5e752169d6
|
|
@ -12,11 +12,14 @@ interface WeatherForecast {
|
||||||
export default class FetchDataComponent extends Vue {
|
export default class FetchDataComponent extends Vue {
|
||||||
forecasts: WeatherForecast[] = [];
|
forecasts: WeatherForecast[] = [];
|
||||||
|
|
||||||
mounted() {
|
async mounted() {
|
||||||
fetch('api/SampleData/WeatherForecasts')
|
try {
|
||||||
.then(response => response.json() as Promise<WeatherForecast[]>)
|
let response = await fetch('api/SampleData/WeatherForecasts');
|
||||||
.then(data => {
|
let data = await response.json();
|
||||||
this.forecasts = data;
|
this.forecasts = data;
|
||||||
});
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue