|
25 | 25 | </v-row>
|
26 | 26 | </v-slide-y-transition>
|
27 | 27 |
|
28 | | - <v-alert |
29 | | - :value="showError" |
30 | | - type="error" |
31 | | - v-text="errorMessage" |
32 | | - > |
| 28 | + <v-alert :value="showError" type="error" v-text="errorMessage"> |
33 | 29 | This is an error alert.
|
34 | 30 | </v-alert>
|
35 | | - |
36 | | - <v-alert |
37 | | - :value="showError" |
38 | | - type="warning" |
39 | | - > |
40 | | - Are you sure you're using ASP.NET Core endpoint? (default at <a href="http://localhost:5000/fetch-data">http://localhost:5000</a>)<br> |
41 | | - API call would fail with status code 404 when calling from Vue app (default at <a href="http://localhost:8080/fetch-data">http://localhost:8080</a>) without devServer proxy settings in vue.config.js file. |
42 | | - </v-alert> |
43 | | - |
| 31 | + |
| 32 | + <v-alert :value="showError" type="warning"> |
| 33 | + Are you sure you're using ASP.NET Core endpoint? (default at |
| 34 | + <a href="http://localhost:5000/fetch-data">http://localhost:5000</a |
| 35 | + >) |
| 36 | + <br /> |
| 37 | + API call would fail with status code 404 when calling from Vue app |
| 38 | + (default at |
| 39 | + <a href="http://localhost:8080/fetch-data">http://localhost:8080</a>) |
| 40 | + without devServer proxy settings in vue.config.js file. |
| 41 | + </v-alert> |
44 | 42 | </v-container>
|
45 | 43 | </template>
|
46 | 44 |
|
47 | 45 | <script lang="ts">
|
48 | | -import { Component, Vue } from 'vue-property-decorator'; |
| 46 | +// an example of a Vue Typescript component using Vue.extend |
| 47 | +import Vue from 'vue'; |
49 | 48 | import { Forecast } from '../models/Forecast';
|
50 | 49 | import axios from 'axios';
|
51 | 50 |
|
52 | | -@Component({}) |
53 | | -export default class FetchDataView extends Vue { |
54 | | - private loading: boolean = true; |
55 | | - private showError: boolean = false; |
56 | | - private errorMessage: string = 'Error while loading weather forecast.'; |
57 | | - private forecasts: Forecast[] = []; |
58 | | - private headers = [ |
59 | | - { text: 'Date', value: 'date' }, |
60 | | - { text: 'Temp. (C)', value: 'temperatureC' }, |
61 | | - { text: 'Temp. (F)', value: 'temperatureF' }, |
62 | | - { text: 'Summary', value: 'summary' }, |
63 | | - ]; |
64 | | - |
65 | | - private getColor(temperature: number) { |
66 | | - if (temperature < 0) { |
67 | | - return 'blue'; |
68 | | - } else if (temperature >= 0 && temperature < 30) { |
69 | | - return 'green'; |
70 | | - } else { |
71 | | - return 'red'; |
72 | | - } |
73 | | - } |
74 | | - private async created() { |
| 51 | +export default Vue.extend({ |
| 52 | + data() { |
| 53 | + return { |
| 54 | + loading: true, |
| 55 | + showError: false, |
| 56 | + errorMessage: 'Error while loading weather forecast.', |
| 57 | + forecasts: [] as Forecast[], |
| 58 | + headers: [ |
| 59 | + { text: 'Date', value: 'date' }, |
| 60 | + { text: 'Temp. (C)', value: 'temperatureC' }, |
| 61 | + { text: 'Temp. (F)', value: 'temperatureF' }, |
| 62 | + { text: 'Summary', value: 'summary' }, |
| 63 | + ], |
| 64 | + }; |
| 65 | + }, |
| 66 | + methods: { |
| 67 | + getColor(temperature: number) { |
| 68 | + if (temperature < 0) { |
| 69 | + return 'blue'; |
| 70 | + } else if (temperature >= 0 && temperature < 30) { |
| 71 | + return 'green'; |
| 72 | + } else { |
| 73 | + return 'red'; |
| 74 | + } |
| 75 | + }, |
| 76 | + async fetchWeatherForecasts() { |
| 77 | + try { |
| 78 | + const response = await axios.get<Forecast[]>('api/WeatherForecast'); |
| 79 | + this.forecasts = response.data; |
| 80 | + } catch (e) { |
| 81 | + this.showError = true; |
| 82 | + this.errorMessage = `Error while loading weather forecast: ${e.message}.`; |
| 83 | + } |
| 84 | + this.loading = false; |
| 85 | + }, |
| 86 | + }, |
| 87 | + async created() { |
75 | 88 | await this.fetchWeatherForecasts();
|
76 | | - } |
77 | | - |
78 | | - private async fetchWeatherForecasts() { |
79 | | - try { |
80 | | - const response = await axios.get<Forecast[]>('api/WeatherForecast'); |
81 | | - this.forecasts = response.data; |
82 | | - } catch (e) { |
83 | | - this.showError = true; |
84 | | - this.errorMessage = `Error while loading weather forecast: ${e.message}.`; |
85 | | - } |
86 | | - this.loading = false; |
87 | | - } |
88 | | -} |
| 89 | + }, |
| 90 | +}); |
89 | 91 | </script>
|
0 commit comments