mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-23 01:58:29 +00:00
Add Vue template
This commit is contained in:
22
templates/VueSpa/ClientApp/components/fetchdata/fetchdata.ts
Normal file
22
templates/VueSpa/ClientApp/components/fetchdata/fetchdata.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import Vue from 'vue';
|
||||
import { Component, Lifecycle } from 'av-ts';
|
||||
|
||||
interface WeatherForecast {
|
||||
dateFormatted: string;
|
||||
temperatureC: number;
|
||||
temperatureF: number;
|
||||
summary: string;
|
||||
}
|
||||
|
||||
@Component
|
||||
export default class FetchDataComponent extends Vue {
|
||||
forecasts: WeatherForecast[] = [];
|
||||
|
||||
@Lifecycle mounted() {
|
||||
fetch('/api/SampleData/WeatherForecasts')
|
||||
.then(response => response.json() as Promise<WeatherForecast[]>)
|
||||
.then(data => {
|
||||
this.forecasts = data;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<template>
|
||||
<div>
|
||||
<h1>Weather forecast</h1>
|
||||
|
||||
<p>This component demonstrates fetching data from the server.</p>
|
||||
|
||||
<table v-if="forecasts.length" class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>Temp. (C)</th>
|
||||
<th>Temp. (F)</th>
|
||||
<th>Summary</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in forecasts">
|
||||
<td>{{ item.dateFormatted }}</td>
|
||||
<td>{{ item.temperatureC }}</td>
|
||||
<td>{{ item.temperatureF }}</td>
|
||||
<td>{{ item.summary }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p v-else><em>Loading...</em></p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script src="./fetchdata.ts"></script>
|
||||
Reference in New Issue
Block a user