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 {
|
||||
forecasts: WeatherForecast[] = [];
|
||||
|
||||
mounted() {
|
||||
fetch('api/SampleData/WeatherForecasts')
|
||||
.then(response => response.json() as Promise<WeatherForecast[]>)
|
||||
.then(data => {
|
||||
this.forecasts = data;
|
||||
});
|
||||
async mounted() {
|
||||
try {
|
||||
let response = await fetch('api/SampleData/WeatherForecasts');
|
||||
let data = await response.json();
|
||||
this.forecasts = data;
|
||||
}
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue