Vue.js template: Use async/await

This commit is contained in:
Murat Girgin 2017-10-04 20:36:45 -07:00 committed by Steve Sanderson
parent 40603f1566
commit 5e752169d6
1 changed files with 9 additions and 6 deletions

View File

@ -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);
}
} }
} }